glutTimerFunc Troubles

I have been using the glutIdleFunc for animation but now I need to time it a bit better. I have tried using a timer callback but it doesnt want to cooperate properly and I dont know why. Here is my code:

void timer( int value )
{
	ball.moveBall( );
	glutPostRedisplay( );
}

int main( int argc, char**argv )
{
	glutInit( &argc, argv );
	glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB );
	glutInitWindowSize( 350, 450 );
	glutInitWindowPosition( 100, 100 );

	glutCreateWindow( "balltest glut program" );

	init( );
	glutDisplayFunc( renderScene );
	glutReshapeFunc( resize );
	glutTimerFunc( 10, timer, 1 );
	glutMouseFunc( mouse );
	glutSpecialFunc( special );
	glutMainLoop( );

	return 1;
}

This worked fine when I was using the idle callback but now it doesnt work at all. Why???

the GLUT timer function is a one-shot timer. you need to reset it every time is generates a callback.

For an alternative (for win32) try Cpw. It has very accurate timer callbacks and timers can be recurring or one-shot. They also take less cpw time to compute.

Regards,
Jim

Try this:

void timer( int value )
{
ball.moveBall( );
glutPostRedisplay( );
glutTimerFunc( 10, timer, 1 );
}

Originally posted by DM:
[b]I have been using the glutIdleFunc for animation but now I need to time it a bit better. I have tried using a timer callback but it doesnt want to cooperate properly and I dont know why. Here is my code:

[quote]

void timer( int value )
{
	ball.moveBall( );
	glutPostRedisplay( );
}

int main( int argc, char**argv )
{
	glutInit( &argc, argv );
	glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB );
	glutInitWindowSize( 350, 450 );
	glutInitWindowPosition( 100, 100 );

	glutCreateWindow( "balltest glut program" );

	init( );
	glutDisplayFunc( renderScene );
	glutReshapeFunc( resize );
	glutTimerFunc( 10, timer, 1 );
	glutMouseFunc( mouse );
	glutSpecialFunc( special );
	glutMainLoop( );

	return 1;
}

This worked fine when I was using the idle callback but now it doesnt work at all. Why???[/b][/QUOTE]