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 2 of 2

Thread: Displaying in a loop--arrrrr...

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2003
    Location
    tyler, tx, usa
    Posts
    14

    Displaying in a loop--arrrrr...

    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.

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Jan 2003
    Location
    Virginia
    Posts
    601

    Re: Displaying in a loop--arrrrr...

    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
    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_DEPTH);
    	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.

Posting Permissions

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