Results 1 to 5 of 5

Thread: How to stop a TimerFunction callback?

  1. #1
    Guest

    How to stop a TimerFunction callback?

    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)
    {
    glRotatef(5.0,0.0f,0.0f,1.0f);
    glutPostRedisplay();
    glutTimerFunc(20, TimerFunction, 1);
    }

  2. #2
    Senior Member Frequent Contributor
    Join Date
    Jan 2003
    Location
    Virginia
    Posts
    586

    Re: How to stop a TimerFunction callback?

    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/libr...ec3/spec3.html

  3. #3
    Senior Member Regular Contributor
    Join Date
    Aug 2003
    Posts
    369

    Re: How to stop a TimerFunction callback?

    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)

  4. #4
    Junior Member Newbie
    Join Date
    Mar 2005
    Posts
    20

    Re: How to stop a TimerFunction callback?

    Humm...
    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...

  5. #5
    Senior Member OpenGL Pro
    Join Date
    Jul 2001
    Location
    France
    Posts
    1,662

    Re: How to stop a TimerFunction callback?

    it's been a while I didn't program in glut... Let's have a try:

    Code :
    int do_i_have_to_rotate = 1;
    [...]
    void TimerFunction(int value)
    {
       glRotatef(5.0,0.0f,0.0f,1.0f);
       glutPostRedisplay();
     
       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...

Similar Threads

  1. Use of TimerFunction, glPushMatrix(); , and glPopmatrix();
    By Cquest in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 01-19-2014, 02:37 PM
  2. Stop blending
    By in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 10-06-2006, 03:05 AM
  3. Stop the madness
    By azcoder in forum OpenGL: Windows
    Replies: 4
    Last Post: 02-01-2006, 05:40 PM
  4. Stop the madness
    By azcoder in forum OpenGL: Advanced Coding
    Replies: 9
    Last Post: 01-24-2006, 10:23 AM
  5. how to stop timerfunc?
    By in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 01-12-2005, 01:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean