• Advertisement


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

calculatin fps revisited

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

Ok, fps...
... so frames per second are how many screens, or scenes you show per second.
For instance, If you use DirectDraw, with a front buffer and a back buffer, you display a new scene, or screen whenever you, after doing all drawing to the backbuffer, flip it with the frontbuffer.

What you have to do is: read the current time, and reset a counter. Then, for each flip, add 1 to the counter. whenever it gets to a certain number, you read the time again, subtract the time you read at the beggining (in seconds) and divide the number of screens by the time difference, that will give you the frames per second. store it in a global or static variable wich you display in every screen (scene/frame), or print it out to a file.

You know, I never wanted to be a programmer...

Alexandre Moura

Share this post

Link to post
Share on other sites
Here''s another way to do it:

// You do this in initaliazation

int old_fps = 0; // The old_fps, temp
int fps = 0; // The actual FPS that should be displayed

int previous_time = GetTickCount(); // temp

// And in the main loop you would:

if (GetTickCount() - previous_time >= 1000) // Has 1 sec passed ?

fps = old_fps;
previous_time = GetTickCount();
old_fps = 0;

Now you display ''fps'' on the screen.
What your basically doing is your checking if a second has passed since the last time you got the time (GetTickCount())
If one second passed, we transfer old_fps to fps (To get the actual fps), reset old_fps to 0 and previous_time to the current time.

The road to success is always under construction

Share this post

Link to post
Share on other sites

  • Advertisement