PDA

View Full Version : Displaying in a loop--arrrrr...



Nelah
03-03-2003, 07:17 PM
I am trying desparately to make a program that'll draw an ellipse with GL_POINTS, but for some reason, the while loop that contains the glutIdleFunc only processes the function the last time through the loop. The while loop runs 6 times, but only transfers control to my display function on the sixth time. What am I doing wrong? (I have also tried glutPostRedisplay) Thanks so much.

shinpaughp
03-03-2003, 08:43 PM
The function you pass to glutIdleFunc basically is used when the code is idle (ie no pending events). So, you typically only call glutIdleFunc once in your main function to tell GLUT to use that function when idle. Then, whenever the program is idle it will use your idleFunc. Or use display func and reshape func. You can also handle keyboard and mouse events. Depends on what you are trying to achieve.

So, do not call glutIdleFunc multiple times in a loop, unless you actually want it to switch between different functions while idling, but that would best be done through glutTimerFunc to allow it time to actually use the various functions if that were your intention.

pseudo-code



void idlefunc()
{
while (criteria)
{
draw stuff
}
glutSwapBuffers();//if using GLUT_DOUBLE
}

int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPT H);
glutInitWindowSize(400,400);
glutInitWindowPosition(100,100);
glutCreateWindow(argv[0]);
init();//initialize clear color, enable depth test, etc
glutIdleFunc(idlefunc);
glutMainLoop();
return 0;
}



The idlefunc will be called continuously while there are no pending events, such as keyboard, mouse, etc if defined. There is no need to try to stay within the idlefunc and maintain the loop indefinitely. It will continue to be called whenever idle occurs.