• Popular Now

• 10
• 11
• 12
• 14
• 15

Archived

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.

Recommended Posts

i need to know how to calculate the fps again because i didnt understand it verywell the first time and i couldnt get it to work either

Share on other sites
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 on other sites
Here''s another way to do it:

  // You do this in initaliazationint old_fps = 0; // The old_fps, tempint fps = 0; // The actual FPS that should be displayedint 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