ugluk
07-04-2010, 09:08 AM
When I want to measure fps I often do something like this in the DisplayFunc:
#ifndef NDEBUG
boost::timer timer;
#endif // NDEBUG
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
GL_DEBUG();
render_loop_ptr->render();
glutSwapBuffers();
#ifndef NDEBUG
glutSetWindowTitle(cformat("%.2f", 1 / timer.elapsed()).c_str());
#endif // NDEBUG
The boost::timer comes from the boost library and is a wrapper around clock(), cformat() is a wrapper around vsnprintf().
The problem is that many times, on a fast graphics card, I get infinite fps as a result. That is, it is as if no time has elapsed in the rendering loop. Is there a portable way to achieve accurate timing? Should I use the GL timer extension?
#ifndef NDEBUG
boost::timer timer;
#endif // NDEBUG
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
GL_DEBUG();
render_loop_ptr->render();
glutSwapBuffers();
#ifndef NDEBUG
glutSetWindowTitle(cformat("%.2f", 1 / timer.elapsed()).c_str());
#endif // NDEBUG
The boost::timer comes from the boost library and is a wrapper around clock(), cformat() is a wrapper around vsnprintf().
The problem is that many times, on a fast graphics card, I get infinite fps as a result. That is, it is as if no time has elapsed in the rendering loop. Is there a portable way to achieve accurate timing? Should I use the GL timer extension?