fps timer
could anyone help me with getting started on creating an fps timer?
~Sethric
November 25, 2003 12:23 PM
Try <a href="http://www.gametutorials.com/Tutorials/OpenGL/OpenGL_Pg1.htm">GameTutorials</a>
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
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
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]
[edited by - sethric on November 25, 2003 1:46:22 PM]
[edited by - sethric on November 25, 2003 1:46:37 PM]
~Sethric
November 25, 2003 01:14 PM
One word of caution,
exercise care in using a float to hold the value of GetTickCount().
The return value is a DWORD (unsigned long). Now, normally this should not be a problem as GetTickCounts should be start at 0 every time the system is turned on. However, keep in mind that not all systems get reboot, and after a around 25 days or so running, the returned ticks will be greater then the DWORD (unsigned long) can be converted down to a float data type. The resulting value is undefined. Meaning, it will most likely be completely wrong. And relying on it for calculations will not work.
Just my 2 cents anyway.
exercise care in using a float to hold the value of GetTickCount().
The return value is a DWORD (unsigned long). Now, normally this should not be a problem as GetTickCounts should be start at 0 every time the system is turned on. However, keep in mind that not all systems get reboot, and after a around 25 days or so running, the returned ticks will be greater then the DWORD (unsigned long) can be converted down to a float data type. The resulting value is undefined. Meaning, it will most likely be completely wrong. And relying on it for calculations will not work.
Just my 2 cents anyway.
what would you suggest in place? a DWORD value?
[edited by - sethric on November 25, 2003 2:19:38 PM]
[edited by - sethric on November 25, 2003 2:19:38 PM]
~Sethric
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement