Timing the redisplay?

Hi im currently using the glutIdleFunc() callback to call glutPostRedisplay() as a way of doing animation in my program. Im concerned about animation speeds on different computers (due to their varrying speeds), so I’m wondering if there is a way to set something like a redisplay every clock tick?

Use elapsed time to pace the animation. This way faster systems get a smoother product.

could you elaborate? I understand what you mean but the implementation I come up with might not be the best? are there examples anywhere I could look at?

Measure the time since the last update using system calls and use that as the basis for your animation. For example if you apply a movement to an object scale it by the elapsed time. Same with things like acceleration etc.

Use glutTimerFunc, and you can set the time interval that you display is updated.
And is not effected by CPU speed.

glutTimerFunc( Time_in_milliseconds, function_to_call, id_number);

Note it is a one shot deal must be reset every time it is called.

void Timer_func( int id )
{

//Do something

glutPostRedisplay();
glutTimerFunc( 100(ms), Timer_func, 0); // Reset timer
}

Originally posted by Molotov:
Hi im currently using the glutIdleFunc() callback to call glutPostRedisplay() as a way of doing animation in my program. Im concerned about animation speeds on different computers (due to their varrying speeds), so I’m wondering if there is a way to set something like a redisplay every clock tick?