View Full Version : How to stop a TimerFunction callback?

03-25-2005, 01:45 PM
I use the TimerFunction below to animate spiral (make it rotate). How can I stop the TimerFunction?? I used a for-loop to test if it can be called only several times, but it did not work.

void TimerFunction(int value)
glutTimerFunc(20, TimerFunction, 1);

03-25-2005, 02:04 PM
According to GLUT spec - There is no support for canceling a registered callback. Instead, ignore a callback based on its value parameter when it is triggered.

The GLUT docs can be found http://www.opengl.org/resources/libraries/glut/spec3/spec3.html

03-25-2005, 03:54 PM
Well, you can always try glutTimerFunc(20, NULL, 0);
That way the callback has no function to call to.
I think this is the best way to cancel callbacks. But you can't disable important callbacks like glutDisplayFunc (reasonably)

03-27-2005, 10:09 PM
But if there is no way to stop the callback, how can I stop an animation? I really don`t get the clue yet. I basically rotate a coordinate system, every x milliseconds. But at a certain point I want it to stop rotating. How would I do this then? Can you post some lines of code please...

03-28-2005, 12:38 AM
it's been a while I didn't program in glut... Let's have a try:

int do_i_have_to_rotate = 1;
void TimerFunction(int value)

if (do_i_have_to_rotate)
glutTimerFunc(20, TimerFunction, 1);
}Simply update the variable 'do_i_have_to_rotate' when you know what to do. You can make another function with another glut timer that will have to take care of managing the variable.
I hope this is not wrong...