Advertisement Jump to content


This topic is now archived and is closed to further replies.


FPS control

This topic is 6886 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

Hello. I have been looking at a lot of FPS code and either didn''t understand them, or saw that they looked really slow and inefficient. So if anyone has some efficiant sample code for frame rate control, please post it up. It would be greatly appreciated. -Thanks "Remember, I'm the monkey, and you're the cheese grater. So no messing around." -Grand Theft Auto, London

Share this post

Link to post
Share on other sites
Here''s what I have:

Start of the main loop:

// if we need the elapsed time, then get it
timeCount = timeGetTime();
frameCount = 0;
timeNeeded = false;

end of main loop:
// count another frame, and if needed update the frame rate
if((timeGetTime() - timeCount) >= 1000)
frameRate = frameCount;
timeNeeded = true;

Sorry about the tabs. I hope that helps! (And I hope I didn''t leave anything out...)

Jonathan Little

Share this post

Link to post
Share on other sites
OK here''s the idea. I''m working on this problem right now. Here''s some basic rough idea code.

long CountTime = timeGetTime();//or whatever in milliseconds
int fps = 30;//# of frames/second
//Somewhere in the main loop

do{}while(timeGetTime() - CountTime < (1000/fps));
CountTime = timeGetTime();

That''s it!
Just start up the CountTime, and every frame wait until the difference between the real time and the one stored from the beginning of the last frame.

Hope it works

-Ben Dilts

Share this post

Link to post
Share on other sites

The process goes as follows (imagine this is your main rendering loop):

while (render)
(1) get a time measurement, which is a representation of the current time (this could be with GetTickCount() or some other higher-precision timer)

(Do all your drawing - this is the bulk of your code)

(2) get another time measurement and subtract the previous
in order to get the elapsed time (in milliseconds).

(3) This is the key. Divide the total time it took to render the frame (elapsed time) into a second. (see: 1000ms). This will tell you how many frames will draw during that whole second.

If you look at the code samples people have provided they
should all follow this basic process.

If you want to limit the frame rate I guess you could either put a short loop (pause) in your rendering loop to slow things down or else write your program so that the number of frames displayed is time bound eg. (display a new frame only every 90ms instead of every 14ms).


Edited by - paulcoz on 3/16/00 6:59:49 PM

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!