Tuesday, May 14, 2013

opengl: glutMainLoopEvent() only loop once

 

http://www.gamedev.net/topic/582980-freeglut-glutmainloopevent-wont-return/

while(1) glutMainLoopEvent();
seems only run once
 
Reason:
glutMainLoopEvent() seems only loop if 
there’s an gl event in same loop with it. 
E.g. the following code will seem to only loop once, 
instead of 100 times as specified
int main(int argc, char **argv) { 

// init GLUT and create Window
addPoints();
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(200,0);
glutInitWindowSize(600,600);
glutCreateWindow("Particle Simulator");
glutDisplayFunc(display);
glutIdleFunc(animation);
glutKeyboardFunc (keyboard);
glutSpecialFunc (keyboardSpecial);

for (int j=0; j < 100; j ++)
{
// enter GLUT event processing cycle
glutMainLoopEvent();
}

return 1;

}
but the following will behave as expected 
(display will call many gl draw function hence seem to work):
int main(int argc, char **argv) {

// init GLUT and create Window
addPoints();
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(200,0);
glutInitWindowSize(600,600);
glutCreateWindow("Particle Simulator");
glutIdleFunc(animation);
glutKeyboardFunc (keyboard);
glutSpecialFunc (keyboardSpecial);

for (int j=0; j < 100; j ++)
{
// display to the screen
display();

// enter GLUT event processing cycle
glutMainLoopEvent();
}

return 1;
}


 

No comments:

Post a Comment