Mike2012
Mike2012

Reputation: 7725

OpenGl Frame rate

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

Upvotes: 3

Views: 3450

Answers (4)

seveland
seveland

Reputation: 179

If you're on Windows, just use Fraps.

http://www.fraps.com/

Upvotes: -1

genpfault
genpfault

Reputation: 52084

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

Upvotes: 1

Goz
Goz

Reputation: 62323

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

Upvotes: 5

jcoder
jcoder

Reputation: 30035

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.

Upvotes: 3

Related Questions