Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: glutIdleFunc slow down animation

  1. #1
    Junior Member Regular Contributor
    Join Date
    Jan 2013
    Posts
    170

    glutIdleFunc slow down animation

    is there anyway to slow down the animation using glutIdleFunc function?

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    3,008
    Quote Originally Posted by pbivens View Post
    is there anyway to slow down the animation using glutIdleFunc function?
    The idle function will be called repeatedly while there are no other events pending. In general, you should only install an idle callback if there's work for it to do, and remove it when there is nothing for it to do, otherwise you'll end up saturating a core calling the idle callback repeatedly.

    If you want to sync to the rate at which you can redraw, update at the start of the display callback and call glutPostRedisplay() at the end of the display callback.

    If you want to execute something approximately at a fixed rate, use a timer callback. You need to set a new timer from the callback to have the callback invoked continuously. Note that the timer callback will be called no earlier than the specified time; this results in the actual rate being slightly lower than expected.

    To perform updates at a consistent rate regardless of the frame rate and without the drift caused by accumulated inaccuracy in the timer callback, check the current time at the start of the display callback and call the update function as many times as needed to catch up. E.g.
    Code :
    void display(void)
    {
        static const double ticks_per_second = 60.0; // or whatever
        static int last;
        int now = glutGet(GLUT_ELAPSED_TIME);
        int tick = (int) floor(now * ticks_per_second / 1000);
        if (!last)
            last = tick-1;
        for ( ; last < tick; last++)
            update();
        draw();
        glutPostRedisplay();
    }
    Last edited by GClements; 12-06-2018 at 05:40 AM.

  3. #3
    Junior Member Regular Contributor
    Join Date
    Jan 2013
    Posts
    170
    good I found this code on the net, thanks for all the help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •