I’ve got 4 cubes made of quads rotating around 0,0,0. The problem is, that the quads appear in the correct order when I render them, but it looks like the cubes are rendered one after the other in a way, that the newly drawn cubes are drawn in front of the old ones.
It’s like no depth sorting was used - but only when rendering the cubes (and not the quads of a cube).
I’ll post a piece of my code (as short as possible), maybe someone will find something I haven’t.
[i]
In “MAIN”:
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);glLoadIdentity();glPushMatrix();
glMatrixMode( GL_PROJECTION );glPushMatrix();glLoadIdentity();
gluPerspective( 80, 1.3, 0,1000.0 );
gluLookAt(0, 0, 5, 0,0,0, 0,1,0);
glEnable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
glTranslated(0,0,0);
glRotated(rot,1,0,0);
draw_cubes();
glMatrixMode(GL_PROJECTION);glPopMatrix();
glMatrixMode(GL_MODELVIEW);glPopMatrix();
SwapBuffers(DCvalue);
[/i]
In the init() I also wrote:
glEnable(GL_NORMALIZE);
glDepthFunc(GL_LEQUAL);
glShadeModel(GL_SMOOTH);
I ‘stole’ the normals and the vertices’ data from the NeHe ‘Missile mapping’ lesson, so, they should be correct:
Quad 1:
normal1=0;normal2=0;normal3=1;
texcoord11=0;texcoord12=0;
texcoord21=1;texcoord22=0;
texcoord31=1;texcoord32=1;
texcoord41=0;texcoord42=1;
x1= 0+x; y1= 0+y; z1=5;
x2= 5+x; y2= 0+y; z2=5;
x3= 5+x; y3= 5+y; z3=5;
x4= 0+x; y4= 5+y; z4=5;
Quad 2:
normal1=0;normal2=0;normal3=-1;
texcoord11=1;texcoord12=0;
texcoord21=1;texcoord22=1;
texcoord31=0;texcoord32=1;
texcoord41=0;texcoord42=0;
x1= 0+x; y1= 0+y; z1= 0;
x2= 0+x; y2= 5+y; z2= 0;
x3= 5+x; y3= 5+y; z3= 0;
x4= 5+x; y4= 0+y; z4= 0;
And so on…
I know, that drawing 2 cubes is a basic thing to do and I’ve done harder tricks already, but now, I’m really stuck… I think I missed someting.
Please, someone help me