Jump to content
  • Advertisement
Sign in to follow this  
zeeli

OpenGL Cube doesn't render properly [SOLVED]

This topic is 3281 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!