calculatin fps revisited

Started by
1 comment, last by omegasyphon 23 years, 7 months ago
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
Advertisement
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
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
Goblineye EntertainmentThe road to success is always under construction

This topic is closed to new replies.

Advertisement