What would be the best way to measure the frame rate of my OpenGL program?
+2
A:
Measure the elapsed time and count the number of frames. Divide one by the other to give frame rate.
When the elapsed time reached one second, or more if you want to average it over a longer time period reset both counts and start again.
John Burton
2009-09-02 22:02:03
If I am using glut and I make this call glutIdleFunc(oneFrame); I am assuming that the oneFrame will be called every frame is this correct?
Mike2012
2009-09-02 22:30:26
I believe so but I'm not that familiar with glut
John Burton
2009-09-03 07:25:24
+2
A:
Stick a timer at the start of your main loop and test how long it takes to get back there.
Under windows you would do something like:
double oldTime = 0.0.
while( !exit )
{
__int64 counter;
QueryPerformanceCounter( (LARGE_INTEGER*)&counter );
__int64 frequency;
QueryPerformanceFrequency( (LARGE_INTEGER*)&frequency );
double newTime = (double)counter / (double)frequency;
double frameRate = 1.0 / (newTime - oldTime);
oldTime = newTime;
// Rest of your game loop goes here.
}
Goz
2009-09-02 22:04:30
What I said only with actual code so +1(Although it does assume windows...)
John Burton
2009-09-03 07:26:10
Not that he mentioned the platform or the language ... so its guessing time ;)
Goz
2009-09-03 08:54:58