Reputation: 863
In the OpenGL code below, used for initialization and for the main function, why is the display function getting called twice? I can't see a call that would be executed other than glutDisplayFunc(display)
;
void init(void)
{
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Set background color to black and opaque
glClearDepth(1.0f); // Set background depth to farthest
glEnable(GL_DEPTH_TEST); // Enable depth testing for z-culling
glEnable(GL_POINT_SMOOTH);
glDepthFunc(GL_LEQUAL); // Set the type of depth-test
glShadeModel(GL_SMOOTH); // Enable smooth shading
gluLookAt(0.0, 0.0, -5.0, /* eye is at (0,0,5) */
0.0, 0.0, 0.0, /* center is at (0,0,0) */
0.0, 1.0, 0.0); /* up is in positive Y direction */
glOrtho(-5,5,-5,5,12,15);
//glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Nice perspective corrections
}
int
main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutCreateWindow("red 3D lighted cube");
glutInitWindowSize(1280,800 ); // Set the window's initial width & height
//glutInitWindowPosition(50, 50); // Position the window's initial top-left corner
//glutReshapeWindow(800,800);
init();
compute();
glutDisplayFunc(display);
glutMainLoop();
return 0; /* ANSI C requires main to return int. */
}
Upvotes: 4
Views: 1576
Reputation: 400139
Your display()
callback is called whenever GLUT decides it wants the application (that's you) to redraw the contents of the window.
Perhaps there is some events happening as the window opens that causes a need to make sure the window is redrawn.
You're not supposed to "care"; just make sure you redraw the content in the display()
function and never mind how many times it gets called.
Upvotes: 6