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: glutTimerFunc Troubles

  1. #1
    Guest

    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:

    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???

  2. #2
    Junior Member Regular Contributor
    Join Date
    Feb 2002
    Posts
    133

    Re: glutTimerFunc Troubles

    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
    --
    Jim Mathies http://www.mathies.com/

    \"The best way to predict the future is to invent it."

  3. #3
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,070

    Re: glutTimerFunc Troubles

    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:

    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???

Posting Permissions

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