View Full Version : How to stop glutTimerFunc animation?

10-24-2012, 06:23 PM
I have an animation started with glutTimerFunc. I want it to last for 5 seconds and stop. How would I do that?


10-25-2012, 02:03 AM
If you look at the function signature

glutTimerFunc(unsigned int timeout, void( *callback )( int data ), int data);

you have a minimal waiting time until your callback is called once. To coarsely approximate the time you already spent doing the animation you can simply calculate

timeSpent = timeout * invocations

and as soon as timeSpent >= 5000 you don't call glutTimerFunc anymore.