Advertisement

OpenGL uses 95% of my friends processor?

Started by January 16, 2003 06:33 PM
6 comments, last by GroZZleR 22 years, 1 month ago
Hey all, A buddy of mine has reported some problems using one of my OpenGL programs. He says its using 95% of his processor, which is obviously too much. So I sent him the basecode, with a square added to it (with 2 colour calls aswell). He says thats causing him to use anywhere from 67% - 95% of the processor. What could be causing this kind of processor usage? Is this normal? What can he do to fix it? And he runs Half-Life in OpenGL with no problem, he has a ATI Rage card (crappy card but shouldn''t struggle with a single coloured card when he can run Half-Life in OpenGL) on a 700mhz machine with 256+ Megs of RAM. Thanks guys.
This is quite normal. Your program is going in a continous loop without giving up time to other threads. Even if you were not drawing anything, you would still use almost 100% of the CPU time, you would just get an outrageous frame rate.

--
Before I couldn''t spell engineer, now I are one!
--Before I couldn't spell engineer, now I are one!
Advertisement
Try something like this in your main-loop:

	// peek messages	while (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) {		if (GetMessage(&msg, NULL, 0, 0)) {			TranslateMessage(&msg);			DispatchMessage(&msg);		}	}	if (app_active) {		// swap our buffers		glLoadIdentity();		SwapBuffers(hdc);		//glClear(GL_COLOR_BUFFER_BIT);	} else		WaitMessage();				// else we just idle (leave the CPU alone) 


And also don''t forget to set your game active/inactive based on WM_ACTIVATE and WM_SIZE (MINIMIZED)

2DNow - Specializing in yesterday''s technology today!
Its normal.

Since its the only program running, the windows tries to give it the most CPU Power

[edited by - snisarenko on January 17, 2003 9:15:48 PM]
very normal....but then again, your getting like 300 fps...you can lighten the load to help even it out a bit.

Try what he said above or create you own max. fps code.

Actually...I know i have some code for controling it (not limiting it), so it only goes as high as 90...that would definatly get the CPU usage down. Its not tought
Hmm I''m guessing how you would write a frame limiter is each frame, increment a fps var, and when it reaches max fps, don''t render anymore, but wouldn''t that cause the animation to skip if it draws 60 frames in 0.2 seconds? How would you keep that from happening or am I looking at it the wrong way?
Advertisement
Seems like first you would need to know (about) how long each frame takes to render. Say each frame takes 5ms (which means you could get 200fps). You only want 90 fps, so you take 1000/90 and you get ~11, which means each frame needs to take about 11ms per frame. Since they only take 5ms, you have to have some kind of delay for 6ms each frame to reach the target fps of 90. Since 1000/90 isnt EXACTLY 11, you might get a few more frames each second but it should be close enough.
"Walk not the trodden path, for it has borne it's burden." -John, Flying Monk
Well it depends what you are doing. If your roating a cube you really cant control/limit it because the cube will change speeds depending on the fps. But if your walking around a little world, yes, you would just not render (which also means no keyboard input, stuff like that). Not rending ONE scene really wont matter, especially at 90 fps.

However your right, I do see a fault in the logic. Movement and shooting or hitting, yes it will all depend on your FPS...but thats only if thats how you run the game, based on how many times it renders. Thats really not accurate. This is how I do it.

Ok so lets take running for example. Every time you press W you move up lets just say 4.0 (doesn't really matter). If 60 FPS is the optimal speed, then at 60 fps you want to move 4.0 upward. If 15 fps is what your getting then you want that number (4.0) to get higher, and at 90 you want it lower. 60fps = 4.0, (OPTIMALFPS/FPS) * 4.0 = movement.
60/15 = 4. 4 * 4.0 = 16.0.
For every W pressed you go up 16.0. Hense the same movement. 60/90 = .6666667: .666667 * 4.0 = 2.666667.

I hope that all makes sense...

[EDIT] DUHH, i forgot to mention that yes every if you get above 90 FPS, you dont render the scene
[EDIT] just typos

[edited by - ThePretender on January 19, 2003 10:35:10 AM]

This topic is closed to new replies.

Advertisement