You are on page 1of 2

4/7/24, 4:14 PM OpenGl Frame rate - Stack Overflow

OpenGl Frame rate [closed]


Asked 14 years, 7 months ago Modified 12 years, 6 months ago Viewed 3k times

Closed. This question is opinion-based. It is not currently accepting answers.

3 Want to improve this question? Update the question so it can be answered with facts and citations by
editing this post.
Closed 7 months ago.

Improve this question

What would be the best way to measure the frame rate of my OpenGL program?

opengl frame-rate

Share Improve this question Follow asked Sep 2, 2009 at 21:56


Mike2012
7,665 15 85 137

4 Answers Sorted by: Highest score (default)

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:


5
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.


}

Share Improve this answer Follow answered Sep 2, 2009 at 22:04


Goz
61.8k 25 127 206

Measure the elapsed time and count the number of frames. Divide one by the other to give frame rate.

3
https://stackoverflow.com/questions/1370361/opengl-frame-rate 1/2
4/7/24, 4:14 PM OpenGl Frame rate - Stack Overflow

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.

Share Improve this answer Follow answered Sep 2, 2009 at 22:02


jcoder
29.8k 20 89 130

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 Sep 2, 2009 at 22:30

I believe so but I'm not that familiar with glut – jcoder Sep 3, 2009 at 7:25

SPF (Seconds Per Frame) is a bit more informative metric.

1 Share Improve this answer Follow answered Sep 3, 2009 at 16:24


genpfault
51.6k 11 88 142

If you're on Windows, just use Fraps.

http://www.fraps.com/
-1
Share Improve this answer Follow answered Sep 22, 2011 at 15:33
seveland
179 12

https://stackoverflow.com/questions/1370361/opengl-frame-rate 2/2

You might also like