idling system call?
Hi all,
I am trying to set up a FPS max in OpenGL.
In the main message loop of my WinMain function, I have this :
while(not done)
{
get a message;
process a message;
if(screen is not minimized)
render;
}
I think this is causing my program to eat 100% CPU all the time. So I want to instate a max FPS and change the loop to this :
while(not done)
{
get a message;
process a message;
if(screen is not minimized)
{
checkFPS;
if(FPS < maxFPS)
render;
else
SYSTEM CALL TO IDLE
}
}
So, what I want to know is : what system call does Windows provide that allows me to return control of the CPU so that I am not using 100% CPU all the time.
Lets say my program is getting 200 FPS @ 100% CPU, and I want to instate a max of 80 FPS, then I want to be using 40%CPU @ 80 FPS.
Is this possible?
Cheers,
-Tim
You can probably use the Sleep function... You pass the number of milliseconds you want to stay idle, as a parameter
if(FPS < maxFPS)
Doing this is a bad idea. It will cause skipping, especially if the system renders to the max FPS very quickly. With that method, the system will stop rendering all of a sudden, causing NO updates. So lets say I have some super computer that can render 60 frames in 0.2 seconds. Now, for the next 0.8 seconds, the scene will NOT be updated, it''ll look frozen.
What I would do is find the amount of time, in miliseconds, that should be allocated for each frame. Lets say you want to have a target framerate of 60 fps. You would divide 1 by 60 and get 0.016 ms. You would then check in your render loop, using a timer, to see if the time elapsed from the last render is greater than the interval, and if so, render the scene.
Doing this is a bad idea. It will cause skipping, especially if the system renders to the max FPS very quickly. With that method, the system will stop rendering all of a sudden, causing NO updates. So lets say I have some super computer that can render 60 frames in 0.2 seconds. Now, for the next 0.8 seconds, the scene will NOT be updated, it''ll look frozen.
What I would do is find the amount of time, in miliseconds, that should be allocated for each frame. Lets say you want to have a target framerate of 60 fps. You would divide 1 by 60 and get 0.016 ms. You would then check in your render loop, using a timer, to see if the time elapsed from the last render is greater than the interval, and if so, render the scene.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement