   Skybox & rotations
  Hi there. I've made a skybox (built by six quads) which has three teapots in it. What I want to do once I'm inside the skybox is to be able to rotate all three teapots by using the mouse, this work but I have two problemsFirst problem:As I start the program all three teapots disappear immideatly. However once I left-click on the mouse and drag it on the window to rotate the teapots then they appear but barely, if I keep rotating they are there...but they keep flickering. I'm not so sure why this happens.Second problem:The second problem is that I want the view in my skybox to rotate according to the rotation of the teapots. In other words if I rotate the teapots clockwise around the y-axis I want to rotate the view inside the skybox clockwise around the y-axis. Rotation of the skybox should happen as long as I keep rotating the teapots. Let's take another example. If I rotate the teapots so I'm "standing" beneath them I should be able to see the top quad of the cube (my skybox) behind them.I tried to do this (the second problem) by applying the same values (the angles) I gave to my teapots (in glRotate in my teapots() function) to the first two parameters of my gluLookAt(the x and y position of the camera) in the skybox() function. While this did move the view around the skybox when I rotated my teapots it was nowhere close to being the way I wanted it. I'm not so sure what to do now and I'm quite a beginner in OpenGL so easy and clear explanations would be highly appreciated. If anything of my explanations are unclear then let me know :)Here's the code, much of it is taken from other tutorials that I have put together to get them to work.void processMouse(int button, int state, int x, int y) {if ((state == GLUT_DOWN) && (button == GLUT_LEFT_BUTTON)){ rotate=true;}else   {    rotate=false;   }mouse_old_x =x;mouse_old_y =y;}void processMouseActiveMotion(int x, int y) {float weight =0.2;if(rotate) {   xRot += (x-mouse_old_x) * weight;   yRot += (y-mouse_old_y) * weight;   }mouse_old_x =x;mouse_old_y =y;}void skybox(){    float quadSize = 1000.0;    glPushMatrix();    glLoadIdentity();    gluLookAt(0,0,0.0,0.0,0.0,1.0,0.0,-1.0,0.0);    glPushAttrib(GL_ENABLE_BIT);    glEnable(GL_TEXTURE_2D);    glDisable(GL_DEPTH_TEST);    glDisable(GL_LIGHTING);    glColor4f(1,1,1,1);    // Render the front quad    glBindTexture(GL_TEXTURE_2D, texture[0]);    glBegin(GL_QUADS);   glTexCoord2f(0, 0); glVertex3f(  quadSize, -quadSize, -quadSize );   glTexCoord2f(1, 0); glVertex3f( -quadSize, -quadSize, -quadSize );   glTexCoord2f(1, 1); glVertex3f( -quadSize,  quadSize, -quadSize );   glTexCoord2f(0, 1); glVertex3f(  quadSize,  quadSize, -quadSize );    glEnd();    // Render the left quad    glBindTexture(GL_TEXTURE_2D, texture[1]);    glBegin(GL_QUADS);   glTexCoord2f(0, 0); glVertex3f(  quadSize, -quadSize,  quadSize );   glTexCoord2f(1, 0); glVertex3f(  quadSize, -quadSize, -quadSize );   glTexCoord2f(1, 1); glVertex3f(  quadSize,  quadSize, -quadSize );   glTexCoord2f(0, 1); glVertex3f(  quadSize,  quadSize,  quadSize );    glEnd();    // Render the back quad    glBindTexture(GL_TEXTURE_2D, texture[2]);    glBegin(GL_QUADS);   glTexCoord2f(0, 0); glVertex3f( -quadSize, -quadSize,  quadSize );   glTexCoord2f(1, 0); glVertex3f(  quadSize, -quadSize,  quadSize );   glTexCoord2f(1, 1); glVertex3f(  quadSize,  quadSize,  quadSize );   glTexCoord2f(0, 1); glVertex3f( -quadSize,  quadSize,  quadSize );    glEnd();    // Render the right quad    glBindTexture(GL_TEXTURE_2D, texture[3]);    glBegin(GL_QUADS);   glTexCoord2f(0, 0); glVertex3f( -quadSize, -quadSize, -quadSize );   glTexCoord2f(1, 0); glVertex3f( -quadSize, -quadSize,  quadSize );   glTexCoord2f(1, 1); glVertex3f( -quadSize,  quadSize,  quadSize );   glTexCoord2f(0, 1); glVertex3f( -quadSize,  quadSize, -quadSize );    glEnd();    // Render the top quad    glBindTexture(GL_TEXTURE_2D, texture[4]);    glBegin(GL_QUADS);   glTexCoord2f(0, 1); glVertex3f( -quadSize,  quadSize, -quadSize );   glTexCoord2f(0, 0); glVertex3f( -quadSize,  quadSize,  quadSize );   glTexCoord2f(1, 0); glVertex3f(  quadSize,  quadSize,  quadSize );   glTexCoord2f(1, 1); glVertex3f(  quadSize,  quadSize, -quadSize );    glEnd();    // Render the bottom quad    glBindTexture(GL_TEXTURE_2D, texture[5]);    glBegin(GL_QUADS);   glTexCoord2f(0, 0); glVertex3f( -quadSize, -quadSize, -quadSize );   glTexCoord2f(0, 1); glVertex3f( -quadSize, -quadSize,  quadSize );   glTexCoord2f(1, 1); glVertex3f(  quadSize, -quadSize,  quadSize );   glTexCoord2f(1, 0); glVertex3f(  quadSize, -quadSize, -quadSize );    glEnd();    // Restore enable bits and matrix    glPopAttrib();    glPopMatrix();    //Return states    glDisable(GL_TEXTURE_2D);    glEnable(GL_DEPTH_TEST);}void teapots(){//Blue teapotglPushMatrix();glColor4f(0.0,0.0,1.0,0.5);glTranslatef(2.0,0.0,-9.0);glRotatef(yRot,1.0,0.0,0.0);   glRotatef(xRot,0.0,1.0,0.0);glutSolidTeapot(1);glPopMatrix();//Green teapotglPushMatrix();glColor4f(0.0,1.0,0.0,0.5);glTranslatef(1.0,0.0,-8.0);glRotatef(yRot,1.0,0.0,0.0);   glRotatef(xRot,0.0,1.0,0.0);glutSolidTeapot(1);glPopMatrix();//Red teapotglPushMatrix();glColor4f(1.0,0.0,0.0,0.5);glTranslatef(0.0,0.0,-7.0);glRotatef(yRot,1.0,0.0,0.0);   glRotatef(xRot,0.0,1.0,0.0);glutSolidTeapot(1);glPopMatrix();}void display(){glEnable(GL_DEPTH_TEST);glClearColor(0.0,0.0,0.0,1.0); glClear(GL_COLOR_BUFFER_BIT); glLoadIdentity(); skybox();teapots();glFlush(); glutSwapBuffers(); }The following variables are global:rotatemouse_old_x mouse_old_yxRotyRotThe mouse functions just describe how the rotation should work. skybox() create the whole skybox while teapots() takes care of drawing all three with their transformations implemented teapots.If anything is unclear then let me know :)   
  First, a skybox should not be used to clear depth. Additionally, disabling depth test also disables depth writes, i.e. your depth buffer won't change. Add the GL_DEPTH_BUFFER_BIT to your glClear call and set glClearDepth to 1.0.Second, I'm not quite sure of what you'd like to achieve. Do you mean you're rotating the camera around the teapots, viewing them from different sides (technically it's the teapots that rotate then, but the other way round it's easier to imagine)?   ;  I removed the enabling/disabling of the depth buffer in my skybox function. Do you mind explaining why its not good to do them in a skybox (or any function that draws an object for that matter)I also added GL_DEPTH_BUFFER_BIT and glClearDepth like you said and it seems to have solved the problem. glClearDepth didn't make any difference once I had added GL_DEPTH_BUFFER_BIT but I assume its default value is 1. As for the second problem..never mind it. I was thinking of the wrong thing :)Thank you very much for the help.   ;  Well, using the skybox to clear depth would require to enable depth writes but you generally don't want to do that since you wouldn't get the same (intial) depth values all over the buffer.Btw, you should consider rendering your skybox after all opaque objects (with depth testing but without depth writes) to reduce overdraw, and if you're using shaders for the skybox, fragment shader executions.So instead of using a skybox or any arbitrary object to clear the depth buffer you'd need to draw a fullscreen quad at the depth you want to "clear" the buffer to (generally 1.0). However, you can see that this introduces some overhead, since the quad must be processed by the entire pipeline (transformation, rastering etc.) and for each fragment you'd get a read/modify/write operation.Using glClear avoids most of the pipeline and generally just results in an optimized write operation, since you tell OpenGL that the current value of the buffer is not relevant anymore. Note that if you're using the stencil buffer, combine depth and stencil clears!Hope that clarifies it a bit.   