I'm trying to create 2 boxes in OpenGL, but they appear inside-out and sometimes they do not overlap correctly. Video http://www.youtube.com/watch?v=IVJu4zJFp7Q
I'm guessing it is a depth issue but I haven't been able to figure out what I'm doing wrong.
Here is the code I'm using to initialize:
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glDisable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
Here is my distplay function glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
drawYellowBox();
drawBlueBox();
And the code I'm using to draw the shapes:
glPushMatrix();
glBegin(GL_QUADS);
glColor3f(0.15, 0.15, 0.0);
// draw front
glVertex3f(-1.0, -1.5, 1.0);
glVertex3f( 1.0, -1.5, 1.0);
glVertex3f( 0.75, 1.5, 0.75);
glVertex3f(-0.75, 1.5, 0.75);
glColor3f(0.3, 0.3, 0.0);
// draw back
glVertex3f( 1.0, -1.5, -1.0);
glVertex3f(-1.0, -1.5, -1.0);
glVertex3f(-0.75, 1.5, -0.75);
glVertex3f( 0.75, 1.5, -0.75);
glColor3f(0.45, 0.45, 0.0);
// draw left
glVertex3f(-1.0, -1.5, -1.0);
glVertex3f(-1.0, -1.5, 1.0);
glVertex3f(-0.75, 1.5, 0.75);
glVertex3f(-0.75, 1.5, -0.75);
glColor3f(0.6, 0.6, 0.0);
// draw right
glVertex3f( 1.0, -1.5, 1.0);
glVertex3f( 1.0, -1.5, -1.0);
glVertex3f( 0.75, 1.5, -0.75);
glVertex3f( 0.75, 1.5, 0.75);
glColor3f(0.75, 0.75, 0.0);
// draw top
glVertex3f(-0.75, 1.5, 0.75);
glVertex3f( 0.75, 1.5, 0.75);
glVertex3f( 0.75, 1.5, -0.75);
glVertex3f(-0.75, 1.5, -0.75);
glColor3f(0.9, 0.9, 0.0);
// draw bottom
glVertex3f(-1.0, -1.5, -1.0);
glVertex3f( 1.0, -1.5, -1.0);
glVertex3f( 1.0, -1.5, 1.0);
glVertex3f(-1.0, -1.5, 1.0);
glEnd();
glPopMatrix();
glPushMatrix();
glTranslatef(0.0,2.5,0.0);
glRotatef(joint_ui_data->getDOF(Keyframe::HEAD), 0.0, 1.0, 0.0);
glBegin(GL_QUADS);
glColor3f(0.0, 0.15, 0.15);
// draw front face
glVertex3f(-0.8, -0.45, 0.8);
glVertex3f( 0.8, -0.45, 0.8);
glVertex3f( 0.75, 0.45, 0.75);
glVertex3f(-0.75, 0.45, 0.75);
glColor3f(0.0, 0.3, 0.3);
// draw back face
glVertex3f( 0.8, -0.45, -0.8);
glVertex3f(-0.8, -0.45, -0.8);
glVertex3f(-0.75, 0.45, -0.75);
glVertex3f( 0.75, 0.45, -0.75);
glColor3f(0.0, 0.45, 0.45);
// draw left face
glVertex3f(-0.8, -0.45, -0.8);
glVertex3f(-0.8, -0.45, 0.8);
glVertex3f(-0.75, 0.45, 0.75);
glVertex3f(-0.75, 0.45, -0.75);
glColor3f(0.0, 0.6, 0.6);
// draw right face
glVertex3f( 0.8, -0.45, 0.8);
glVertex3f( 0.8, -0.45, -0.8);
glVertex3f( 0.75, 0.45, -0.75);
glVertex3f( 0.75, 0.45, 0.75);
glColor3f(0.0, 0.75, 0.75);
// draw top
glVertex3f(-0.75, 0.45, 0.75);
glVertex3f( 0.75, 0.45, 0.75);
glVertex3f( 0.75, 0.45, -0.75);
glVertex3f(-0.75, 0.45, -0.75);
glColor3f(0.0, 0.9, 0.9);
// draw bottom
glVertex3f(-0.8, -0.45, -0.8);
glVertex3f(-0.8, -0.45, 0.8);
glVertex3f( 0.8, -0.45, 0.8);
glVertex3f( 0.8, -0.45, -0.8);
glEnd();
glPopMatrix();
Thank you.