PDA

View Full Version : glutTimerFunc Troubles



02-16-2002, 09:34 AM
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???

jmathies
02-16-2002, 11:53 AM
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

nexusone
02-18-2002, 05:17 AM
Try this:

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


Originally posted by DM:
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???