Fps counter using OpenGL?

How do i make a simple Frames per second counter using OpenGL for Visual c++ 6.0???

an example would be much appreciated.

You can’t make a frame rate counter with OpenGL, cause OpenGL doesn’t provide any timer functions. Use some system timers instead, like timeGetTime or QueryPerformanceCounter. Look in MSDN for more details on how to use them.

There’s a few ways to calculate the FPS, all based on the same formula. FPS = frames / time, where frames is the number of frames rendered, and time is the time taken to render them. For example, measure the time taken to render one or ten (or as many as you like) frames, or count the number of frames rendered in a second.


Check on my site, I’ve a little example who use a fps counter.

go to http://www.gametutorials.com they have good tutorails for opengl and one ids the fps counter check it out

they are all for VC++

Thanks for all your replies

If you use Glut libraires it’s very easy, you have to take the time with the function “glutGet (GLUT_ELAPSED_TIME)” and make a substraction with the previous value:

time = glutGet(GLUT_ELAPSED_TIME);
if ((time - base_time) > 1000.0)
fps=frames*1000.0/(time - base_time);
base_time = time;

The variable “frames” is a counter of frames, and It’s to be incremented in each frame (Usually in Draw function).