5

When I draw a cube with this code

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt(
x,    y,    z, 
x+xp, y+yp, z+zp,
0.0f, 1.0f, 0.0f);   
glBegin(GL_QUADS);            

glColor3f(0.0f,1.0f,0.0f);            
glVertex3f( 1.0f, 1.0f,-1.0f);        
glVertex3f(-1.0f, 1.0f,-1.0f);       
glVertex3f(-1.0f, 1.0f, 1.0f);       
glVertex3f( 1.0f, 1.0f, 1.0f);        

glColor3f(1.0f,0.5,0.0f);           
glVertex3f( 1.0f,-1.0f, 1.0f);        
glVertex3f(-1.0f,-1.0f, 1.0f);        
glVertex3f(-1.0f,-1.0f,-1.0f);       
glVertex3f( 1.0f,-1.0f,-1.0f);        

glColor3f(1.0f,0.0f,0.0f);            
glVertex3f( 1.0f, 1.0f, 1.0f);        
glVertex3f(-1.0f, 1.0f, 1.0f);       
glVertex3f(-1.0f,-1.0f, 1.0f);        
glVertex3f( 1.0f,-1.0f, 1.0f);        

glColor3f(1.0f,1.0f,0.0f);            
glVertex3f( 1.0f,-1.0f,-1.0f);        
glVertex3f(-1.0f,-1.0f,-1.0f);        
glVertex3f(-1.0f, 1.0f,-1.0f);        
glVertex3f( 1.0f, 1.0f,-1.0f);        

glColor3f(0.0f,0.0f,1.0f);            
glVertex3f(-1.0f, 1.0f, 1.0f);       
glVertex3f(-1.0f, 1.0f,-1.0f);        
glVertex3f(-1.0f,-1.0f,-1.0f);       
glVertex3f(-1.0f,-1.0f, 1.0f);        

glColor3f(1.0f,0.0f,1.0f);            
glVertex3f( 1.0f, 1.0f,-1.0f);        
glVertex3f( 1.0f, 1.0f, 1.0f);        
glVertex3f( 1.0f,-1.0f, 1.0f);       
glVertex3f( 1.0f,-1.0f,-1.0f);   
glEnd();

I get an odd cude drawing:

img1

and

img2

Even without gluLookAt() I still end up with an odd drawing.

The weird thing is I used the exact same code in a python OpenGL project and had no trouble with it. So it seems to be a C error?

It also seems like the first 2 quads (green and orange) are not being drawn at all.

KK.
  • 783
  • 8
  • 20
WIll Cobb
  • 113
  • 9

1 Answers1

4

Just solved my own problem by adding:

glEnable(GL_DEPTH_TEST); 

to my code.

WIll Cobb
  • 113
  • 9