PDA

View Full Version : How to save some CPU time?



monka
09-03-2002, 10:27 PM
Hello

I have a simple animation in 2D using OpenGL and when I run it, it takes almost 95% of the CPU. Why? How can I decrease this usage?

Regards

witcomb
09-04-2002, 03:06 AM
Try limiting the rendering rate to say 30hz. To do this you will have to determine how long you spent rendering and then sleep for the remaining time in that particular frame. This will ofcourse free up your cpu but this may not be what you are wanting to do.

In most cases, I would imagine that your program is running a single animation loop and it attempts to run this continously as fast as it can. Which by the sounds of it is happening. This is great but if you want to decrease the cpu usage, you will have have it rest every once and a while, these sleep operations will do that for you.

Neil Witcomb

JoeMac
09-04-2002, 03:49 AM
Something as simple as synchronising to the monitor refresh may help. If you are not doing this you may be rendering many times for each actual 'draw'.
Joe

Morglum
09-04-2002, 04:05 AM
You can even tell your program to redraw only once every 3 monitor refreshes... in any case, the extension to use is WGL_EXT_swap_control

monka
09-04-2002, 05:51 AM
Originally posted by Morglum:
You can even tell your program to redraw only once every 3 monitor refreshes... in any case, the extension to use is WGL_EXT_swap_control

Hi
Can you send me or point me to an example which uses this mechanism?

Thanks