Limiting the framerate

Started by
4 comments, last by IFASS 19 years, 10 months ago
Hi, is it possible to limit the framerate for example on 80fps? just in c++, opengl and dx3d mode. Engine: Neoengine open-sourced fraggin'' - www.openfrag.org
Advertisement
Yes.
I was influenced by the Ghetto you ruined.
wrong forum, really.
yes, i know it''s possible, but question is wrong.. how can you do it?
http://www.gamedev.net/community/forums/topic.asp?whichpage=1&pagesize=20&topic_id=227559

Has an example in it.
in your game loop you should keep track of how long each frame takes. Get a value in milliseconds, you can use QueryPerformanceCounter for that. Once you figured out how long your frame took to render, use the sleep function to wait the appropriate amount of time before rending the next frame.

80 fps = 1000/80 milliseconds per frame...

say your frame took t milliseconds to render, use:

Sleep(1000.0f/80.0f-t);

You''ll wanna do a check that value is not negative before you do that tho... i''m not quite sure what would happen if you passed a negative value to the sleep command.

This topic is closed to new replies.

Advertisement