PDA

View Full Version : glTimerFunc



10-28-2000, 08:14 AM
I am having trouble getting the
glutTimerFunc callback working. Would someone be able to give me a piece of sample code demonstrating how to use this properly?

Glossifah
10-28-2000, 09:53 AM
Within main(), call it like so:

glutTimerFunc(1000, dispFramerate, 1);

This tells glut to call the specified function dispFramerate() every 1000 milliseconds (1 second) and pass the value 1.

Then, you can set up a function like this:

void dispFramerate(int i)
{
cout << frames << " frames per second" << endl;
frames = 0;
// we have to fire of the timer again at the end of this, so that it will reset and
// fire off again
glutTimerFunc(1000, dispFramerate, 1);
}

This example is from a standard demo setup that I use to display the framerate in the DOS term while running something in the GL context. Calling system("cls"); at the beginning of the function is optional; it will clear the terminal before updating with the frame rate. Oh, frames is a global int that is updated as the last step before calling glutSwapBuffers(); by the way.

Does that help, or should I expand on the explanation?

Glossifah

10-28-2000, 10:49 AM
That is just what I needed to know, thank you!