Jump to content
  • Advertisement
Sign in to follow this  
Dmnbp7ip

OpenGL Limit the fps with opengl...

This topic is 4078 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everyone, I am developping an application that uses OpenGL, and I met a problem : the FPS is not limited, so that the main loop is going and going at "Far-Too-Much" FPS, and that eats my CPU ! I only use SwapBuffers(hDC) in my code in order to display the backbuffer. Does anyone know if there is something like the DirectX property : d3dpp.PresentationInterval=D3DPRESENT_INTERVAL_ONE ??? Thanks, Thomas

Share this post


Link to post
Share on other sites
Advertisement

Thank you, I did not see it...

OK, that works fine. It limits my refresh rate to 60Hz... but it seems it does not limit my CPU consumption ! As if the synchrnization does not block the program, does it ? The directX function actually does it.

If as I think this is just a by pass for the display, is there a way to synchronize my main loop on the refresh rate ??



Share this post


Link to post
Share on other sites
You should be using a timer to time everything isntead of depending on how many frames the game gets drawn...because maby someone's computer is really old can't draw the game at 60fps, then all the animation would be messed up.

You might need to put a sleep() function in your loop. Also, it is a good thing that games run using the full CPU because then it can draw faster and better quality and higher FPS then if you only us part of the cpu.

Share this post


Link to post
Share on other sites

OK, thanks. Actually, I am not developping a game but I use opengl for a graphical interface. That is why I do not want it to use 100% of my CPU. But I think I will use Sleep(), that should be ok.

Thanks guys !

Share this post


Link to post
Share on other sites
In that case, you could just update the screen on a WM_PAINT message and of course, you would use InvalidateRect() here and there.

Share this post


Link to post
Share on other sites
If you're using WinAPI and want to limit the framerate of the program while also conserving CPU for other tasks, use a timer to make the program thread wait for as long as needed. Example:

LARGE_INTEGER liDueTime;
liDueTime.QuadPart=-166666; //60Hz

hTimer = CreateWaitableTimer(NULL, TRUE, "WaitableTimer");
SetWaitableTimer(hTimer, &liDueTime, 0, NULL, NULL, 0);

InitProgram();

while(!done){
SetWaitableTimer(hTimer, &liDueTime, 0, NULL, NULL, 0);
Tick();
Render();
SwapBuffers(hDC);
WaitForSingleObject(hTimer, INFINITE);
}//while(!done)


This will let you run the program at a very precise framerate without using any more CPU than is necessary to do so.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!