Cube doesn't render properly [SOLVED]

Started by
1 comment, last by zeeli 14 years, 5 months ago
Hi. I'm drawing a cube in opengl, but it looks like this: and in wireframe: I'm drawing the cube like this:

//Topface
glBegin(GL_QUADS);
	glVertex3d(m_t1.m_x, m_t1.m_y, m_t1.m_z);
	glVertex3d(m_t2.m_x, m_t2.m_y, m_t2.m_z);
	glVertex3d(m_t3.m_x, m_t3.m_y, m_t3.m_z);
	glVertex3d(m_t4.m_x, m_t4.m_y, m_t4.m_z);
glEnd();

//Frontface
glBegin(GL_QUADS);
	glVertex3d(m_b4.m_x, m_b4.m_y, m_b4.m_z);
	glVertex3d(m_b1.m_x, m_b1.m_y, m_b1.m_z);
	glVertex3d(m_t1.m_x, m_t1.m_y, m_t1.m_z);
	glVertex3d(m_t4.m_x, m_t4.m_y, m_t4.m_z);
glEnd();

//Backface
glBegin(GL_QUADS);
	glVertex3d(m_b2.m_x, m_b2.m_y, m_b2.m_z);
	glVertex3d(m_b3.m_x, m_b3.m_y, m_b3.m_z);
	glVertex3d(m_t3.m_x, m_t3.m_y, m_t3.m_z);
	glVertex3d(m_t2.m_x, m_t2.m_y, m_t2.m_z);
glEnd();

//Leftface
glBegin(GL_QUADS);
	glVertex3d(m_b3.m_x, m_b3.m_y, m_b3.m_z);
	glVertex3d(m_b4.m_x, m_b4.m_y, m_b4.m_z);
	glVertex3d(m_t4.m_x, m_t4.m_y, m_t4.m_z);
	glVertex3d(m_t3.m_x, m_t3.m_y, m_t3.m_z);
glEnd();

//Rightface
glBegin(GL_QUADS);
	glVertex3d(m_b1.m_x, m_b1.m_y, m_b1.m_z);
	glVertex3d(m_b2.m_x, m_b2.m_y, m_b2.m_z);
	glVertex3d(m_t2.m_x, m_t2.m_y, m_t2.m_z);
	glVertex3d(m_t1.m_x, m_t1.m_y, m_t1.m_z);
glEnd();


The corner positions are set like this:

m_t1.m_x = m_position.m_x + 0.50; m_t1.m_y = m_position.m_y + 0.50; m_t1.m_z = m_position.m_z + 0.50;
m_t2.m_x = m_position.m_x + 0.50; m_t2.m_y = m_position.m_y + 0.50; m_t2.m_z = m_position.m_z - 0.50;
m_t3.m_x = m_position.m_x - 0.50; m_t3.m_y = m_position.m_y + 0.50; m_t3.m_z = m_position.m_z - 0.50;
m_t4.m_x = m_position.m_x - 0.50; m_t4.m_y = m_position.m_y + 0.50; m_t4.m_z = m_position.m_z + 0.50;

m_b1.m_x = m_position.m_x + 0.50; m_b1.m_y = m_position.m_y - 0.50; m_b1.m_z = m_position.m_z + 0.50;
m_b2.m_x = m_position.m_x + 0.50; m_b2.m_y = m_position.m_y - 0.50; m_b2.m_z = m_position.m_z - 0.50;
m_b3.m_x = m_position.m_x - 0.50; m_b3.m_y = m_position.m_y - 0.50; m_b3.m_z = m_position.m_z - 0.50;
m_b4.m_x = m_position.m_x - 0.50; m_b4.m_y = m_position.m_y - 0.50; m_b4.m_z = m_position.m_z + 0.50;


m_position is the position of the cube (center) What am I doing wrong? [Edited by - zeeli on October 30, 2009 4:49:17 AM]
Advertisement
Do you have depth testing or blending on?

Can you get the code from NeHe Lesson 5 to run?
http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=05


Tip:

You can group the render calls on one glBegin(GL_QUADS)/glEnd() pair. You get (marginal) performance gain there.
Rioki - http://www.rioki.org
Heh. It was the depth testing which caused the problem.

Thanks mate!

PS. I didn't know about grouping those calls, so thanks for that too :)

This topic is closed to new replies.

Advertisement