Hi. I have a very single openGL program that is supposed to rotate a cube. However, when the program runs and the window opens, the cube just stays still, without moving as I expect.
However, when I maximize and then minimize the window, it rotates (just once). Then if I maximize and minimize again, it rotates again a bit more and so it happens whenever I repeat such procedure.
The question is why? Here is the Opengl code (minus the cube’s code) with a bit of the window code to add context of what is being used where:
glEnable (GL_DEPTH_TEST);
while (5) {
XNextEvent (dpy,&xev);
printf ("Boto!");
if (xev.type == Expose) {
XGetWindowAttributes (dpy,win,&gwa);
glViewport (0,0,gwa.width,gwa.height);
display (width,height);
glXSwapBuffers (dpy,win);
}
else if (xev.type == KeyPress) {
glXMakeCurrent (dpy,None,NULL);
glXDestroyContext (dpy,glc);
XDestroyWindow (dpy,win);
XCloseDisplay (dpy);
break;
}
}
void display(int width, int height) {
glClearColor (0,0,0,0);
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluPerspective (45,(GLfloat)width/(GLfloat)height,1,100);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();
gluLookAt (0,0,10,0,0,0,0,1,0);
glTranslatef (0,3,0);
glRotatef (rot_angle,0,0,1);
glBegin (GL_QUADS);
glVertex3f (-.75, -.75, 0); glColor3f (1,0,0);
.....
glEnd ();
rot_angle+=1.2;
}