Reputation: 326
I am doing an excercise where I draw three boxes across three windows using GLUT. They draw individually, but in the same project, the three windows display correctly, but immediately close the program with code 1.
glutInitWindowPosition(x,y);
windowOne = glutCreateWindow("windowOne");
glClearColor(1.0, 1.0, 1.0, 0.0);
glMatrixMode(GL_PROJECTION);
glOrtho(-400, 400, -400, 400, -500, 500);
glutInitWindowPosition(x,y);
windowTwo = glutCreateWindow("windowTwo");
glClearColor(1.0, 1.0, 1.0, 0.0);
glMatrixMode(GL_PROJECTION);
glFrustum(-60, 60, -60, 60, 60, 200);
gluLookAt(0, 0, 120, 0, 0, 0, 0, 1, 0);
With each window in a separate file loaded in by itself, they each display exactly as they are meant to. I have a feeling I should be setting the window at some point between each init, but I don't know why. I do not have a draw function in at the moment, as I wanted to confirm this happens without the drawing code.
I should also note that I have to create separate windows, exactly as I have done, so other window drawing functions are useless.
Upvotes: 1
Views: 1905
Reputation: 326
I found the answer scouring through examples, so I'll post it just in case anyone else is having similar problems.
the draw function needs to be added after each window, in the style of
// window one
glutInitWindowPosition(50, 50);
WindowOne = glutCreateWindow("orthogonal projection");
glutDisplayFunc(drawWindowOne);
// window two
glutInitWindowPosition(650, 50);
WindowThree = glutCreateWindow("3D viewing system with glFrustum()");
glutDisplayFunc(drawWindowTwo);
I was using a draw function that shuffles through each window and generates its specific draw after using glutSetWindow. each draw takes place after each window is initialized, and multiple glutDisplayFunc() can be called after eachother.
I originally thought I was using glutDisplayFunc to set a pointer, so that when the display routine went through for the frame, it would only generate the last display function called, as opposed to all of them.
Upvotes: 2
Reputation: 162327
Never do OpenGL drawing operations in the same function in which you also create GLUT windows. It doesn't work. You need to register a display callback function for each window and do all drawing there. Calling glutMainLoop is mandatory if you want to see something sensible using GLUT.
Upvotes: 0