PDA

View Full Version : using GLUT and calling an infinite loop routine won't work ?



bilsch01
04-19-2015, 08:54 AM
I wrote a C program, using SDL for graphics, to plot periodic graphs. The plotting of the graph is done in an infinite WHILE loop - the SDL rendering statements are in line in the infinite loop. Now I want to do it using OpenGL and GLUT. The only way I can think to do this is to incorporate the infinite loop with the OpenGL rendering routine called by the GLUT timer function. So far I haven't been able to do it. As I understand it many video games use an infinite loop. Any suggestions? TIA. Bill S.

GClements
04-19-2015, 10:56 AM
If you're using GLUT, the main loop (and the switch statement inside it) are provided for you, by glutMainLoop().

This calls the callbacks registered with glutDisplayFunc(), glutIdleFunc(), etc when appropriate.

If you want continuous animation, you would typically call glutPostRedisplay() at the end of the display function, or in a timer function.

reader1
04-20-2015, 07:20 AM
I wrote a C program, using SDL for graphics, to plot periodic graphs. The plotting of the graph is done in an infinite WHILE loop - the SDL rendering statements are in line in the infinite loop. Now I want to do it using OpenGL and GLUT. The only way I can think to do this is to incorporate the infinite loop with the OpenGL rendering routine called by the GLUT timer function. So far I haven't been able to do it. As I understand it many video games use an infinite loop. Any suggestions? TIA. Bill S.

glutMainLoop() is also a infinite while loop. When some massage like keybord, mouse etc toggle it the program will jump out of the while loop, when finish, it will return to the while loop again.
so that you can design your callback program, and in the main program to call them before glutMainLoop();