[SOLVED]Cube is rendering faces out of order!

The faces are being rendered in the order that I coded them! What do I do?!

INIT CODE

		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		gluPerspective(fov, aspect, near, far);
		glMatrixMode(GL_MODELVIEW);

Cube rendering code

glPushMatrix();
		glBegin(GL_QUADS);
		{
			glColor3f(0.0f, 1.0f, 0.0f);     // Set The Color To Green
	        glVertex3f(1.0f, 1.0f, -1.0f);   // Top Right Of The Quad (Top)
	        glVertex3f(-1.0f, 1.0f, -1.0f);  // Top Left Of The Quad (Top)
	        glVertex3f(-1.0f, 1.0f, 1.0f);   // Bottom Left Of The Quad (Top)
	        glVertex3f(1.0f, 1.0f, 1.0f);    // Bottom Right Of The Quad (Top)

	        glColor3f(1.0f, 0.5f, 0.0f);     // Set The Color To Orange
	        glVertex3f(1.0f, -1.0f, 1.0f);   // Top Right Of The Quad (Bottom)
	        glVertex3f(-1.0f, -1.0f, 1.0f);  // Top Left Of The Quad (Bottom)
	        glVertex3f(-1.0f, -1.0f, -1.0f); // Bottom Left Of The Quad (Bottom)
	        glVertex3f(1.0f, -1.0f, -1.0f);  // Bottom Right Of The Quad (Bottom)

	        glColor3f(1.0f, 0.0f, 0.0f);     // Set The Color To Red
	        glVertex3f(1.0f, 1.0f, 1.0f);    // Top Right Of The Quad (Front)
	        glVertex3f(-1.0f, 1.0f, 1.0f);   // Top Left Of The Quad (Front)
	        glVertex3f(-1.0f, -1.0f, 1.0f);  // Bottom Left Of The Quad (Front)
	        glVertex3f(1.0f, -1.0f, 1.0f);   // Bottom Right Of The Quad (Front)

	        glColor3f(1.0f, 1.0f, 0.0f);     // Set The Color To Yellow
	        glVertex3f(1.0f, -1.0f, -1.0f);  // Bottom Left Of The Quad (Back)
	        glVertex3f(-1.0f, -1.0f, -1.0f); // Bottom Right Of The Quad (Back)
	        glVertex3f(-1.0f, 1.0f, -1.0f);  // Top Right Of The Quad (Back)
	        glVertex3f(1.0f, 1.0f, -1.0f);   // Top Left Of The Quad (Back)

	        glColor3f(0.0f, 0.0f, 1.0f);     // Set The Color To Blue
	        glVertex3f(-1.0f, 1.0f, 1.0f);   // Top Right Of The Quad (Left)
	        glVertex3f(-1.0f, 1.0f, -1.0f);  // Top Left Of The Quad (Left)
	        glVertex3f(-1.0f, -1.0f, -1.0f); // Bottom Left Of The Quad (Left)
	        glVertex3f(-1.0f, -1.0f, 1.0f);  // Bottom Right Of The Quad (Left)

	        glColor3f(1.0f, 0.0f, 1.0f);     // Set The Color To Violet
	        glVertex3f(1.0f, 1.0f, -1.0f);   // Top Right Of The Quad (Right)
	        glVertex3f(1.0f, 1.0f, 1.0f);    // Top Left Of The Quad (Right)
	        glVertex3f(1.0f, -1.0f, 1.0f);   // Bottom Left Of The Quad (Right)
	        glVertex3f(1.0f, -1.0f, -1.0f);  // Bottom Right Of The Quad (Right)
		}
		glEnd();
		glPopMatrix();

glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);

Add it to your GL initialisation.

This form of OpenGL rendering is very, very deprecated.

[s]anyway add

glEnable(GL_DEPTH_TEST);
[/s]

with your init calls and make sure your

glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

edit: beat me to it :slight_smile: still make sure your glClear is right

I suggest atleast starting with vertex arrays, or VBOs

google:

vertex buffer objects

or

vertex arrays

also:

glprogramming.com/red/

(a little outdated but much better than immediate mode)

What does your initGL() method look like now?

Yes. Depth testing still applies.

Just because GL11 is deprecated doesn’t mean ALL of it is deprecated.

Things like glEnable(), glDrawArrays/Elements() etc. are still used in later versions of the API.
It’s just the things used only for immediate mode.

Make sure you’re requesting a depth buffer when you create your display, otherwise GL_DEPTH_TEST won’t have anything to work against.

Can we see your initialization method? It has to be the depth testing. There’s no other reason its doing that.