Hi, I am pretty new to OpenGL and only really feel like I am beginning to understand what is going on. I am trying to get a basic sky box to appear around a previously finished project/lesson however it is the first thing that I have done that I have not had a good tutorial for. This may be completely the wrong way to go about doing this but here is the code I have so far to create the skybox:
void skybox(void) {
glPushMatrix();
glClear(GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt( 0.0, 0.0, 0.0,
1.0, 0.0, 0.0,
0.0, 1.0, 0.0);
glPushAttrib(GL_ENABLE_BIT);
glEnable(GL_TEXTURE_2D);
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
glDisable(GL_BLEND);
glDepthMask(0);
glColor4f(1.0, 1.0, 1.0, 1.0);
glBegin(GL_QUADS); //FRONT
glVertex3f(-1, 1, 1);
glVertex3f( 1, 1, 1);
glVertex3f( 1, -1, 1);
glVertex3f(-1, -1, 1);
glEnd();
glBegin(GL_QUADS); //BACK
glVertex3f(-1, 1, -1);
glVertex3f( 1, 1, -1);
glVertex3f( 1, -1, -1);
glVertex3f(-1, -1, -1);
glEnd();
glBegin(GL_QUADS); //TOP
glVertex3f(-1, 1, 1);
glVertex3f(-1, 1, -1);
glVertex3f( 1, 1, -1);
glVertex3f( 1, 1, 1);
glEnd();
glBegin(GL_QUADS); //BOTTOM
glVertex3f(-1, -1, 1);
glVertex3f( 1, -1, 1);
glVertex3f( 1, -1, -1);
glVertex3f(-1, -1, -1);
glEnd();
glBegin(GL_QUADS); //RIGHT SIDE
glVertex3f( 1, 1, 1);
glVertex3f( 1, -1, 1);
glVertex3f( 1, -1, -1);
glVertex3f( 1, 1, -1);
glEnd();
glBegin(GL_QUADS); //LEFT SIDE
glVertex3f(-1, 1, 1);
glVertex3f(-1, -1, 1);
glVertex3f(-1, -1, -1);
glVertex3f(-1, 1, -1);
glEnd();
glPopAttrib();
glDepthMask(1);
glPopMatrix();
}
At the moment it clears the buffer bit, resets the camera, disables a bunch of stuff including the depth buffer, draws a 2 unit white cube about the origin (the background of the project is currently black so I should be able to tell when I get it working), and then reverts back to old attrib settings.
I am calling this at the beginning of my display function before anything else is rendered. Currently all that happens is that a white square appears behind everything else I am drawing which I think must mean that at least one of the faces of the cube is being drawn but no others.
If anyone could help me out and point me in the right direction I would be very grateful. Also if anyone knows of a good tutorial to achieve a skybox which they think would be good for a beginner please send me the link.
Thanks
Edit:
I thought it might be useful to include the display code:
glutDisplayFunc(display);
void display(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
skybox();
gluLookAt( 0.0, 10.0, 20.0,
0.0, 10.0, 0.0,
0.0, 1.0, 0.0);
init_lights();
glCallList(ground);
render_windmill(0.0, 0.0);
glFlush();
glutSwapBuffers();
return;
}