Skip to main content
GameDev.net gamedev.net
🔒 Locked

fps timer

Started by Sethric Nov 25, 2003 at 12:02 PM 7 replies 750+ views
Original Post
Sethric
Sethric
could anyone help me with getting started on creating an fps timer?
~Sethric
BriW111
BriW111
The Basic idea behind a FPS counter is to calculate how fast your rendering to your screen. At the beginning of your "main loop" set a static or global variable equal to the current time...you can do this several ways, by using GetTickCount() (realize it returns milliseconds) and then increasing a counter that keeps track of the frames.

What you do:

static float starttime = 0, endtime = 0;
static in framerate;

RenderScene()
{
endtime = GetTickCount() * .001; //set it to seconds, not milliseconds
framerate++;
if(endtime - startime > 1)
{
display the counter on your window
endtime = startime
framerate = 0
}

blah blah blah
}

basically you update the framerate to the screen every second, and have a counter to see how many frames you rendered within that second


this style came frome www.gametutorials'' FPS tutorial, under the opengl section



Sethric
Sethric
under the 3rd variable (static in framerate) would that second part be an int? rather than in.

[edited by - sethric on November 25, 2003 1:46:22 PM]

[edited by - sethric on November 25, 2003 1:46:37 PM]
~Sethric
BriW111
BriW111
LOL yeah sorry about that typo. it would be of type int
Sethric
Sethric
what would you suggest in place? a DWORD value?

[edited by - sethric on November 25, 2003 2:19:38 PM]
~Sethric
BriW111
BriW111
wow, that is something that i did not know. i understood that the conversion was a bit sketchy, but considering the values i thought would be passed in, i did not deem this a problem. Hmm....guess i better make sure to reboot every 49 days hehe :-D

if you really want to, you can probably use either an unsigned long (as is GetTickCount) or unsigned long double. if you use the former then skip converting to seconds (again, GetTickCount uses milliseconds) and base your code from there.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.