Hi,
I am trying to define a 3D cube. Is this correct?
glVertex3f(-1,1,0);
glVertex3f(1,1,0);
glVertex3f(1,-1,0);
glVertex3f(-1,-1,0);
glVertex3f(0,0,-1);
glVertex3f(0,0,1);
Thanks
How the vertices will be interpreted depends on what you pass to glBegin(), but either way your code will not define a cube. See here for more info.
Quote:Original post by mbanghart
Hi,
I am trying to define a 3D cube. Is this correct?
glVertex3f(-1,1,0);
glVertex3f(1,1,0);
glVertex3f(1,-1,0);
glVertex3f(-1,-1,0);
glVertex3f(0,0,-1);
glVertex3f(0,0,1);
Thanks
Where are the glBegin and glEnd calls?
First off don't use GL_POLYGON ever, and you need glBegin() and glEnd() when you draw polygons in immediate mode.
there look through that, and check out the beautiful colored cube.
glBegin(GL_QUADS);glColor3f(0.0f,1.0f,0.0f);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 OrangeglVertex3f( 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 RedglVertex3f( 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 YellowglVertex3f( 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 BlueglVertex3f(-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 VioletglVertex3f( 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(); // Done Drawing The Quad
there look through that, and check out the beautiful colored cube.
Thanks. But this is for a school project and I have to use polygons. The cube is being displayed 2D (and I have to use 6 vertices) and my input data is 3D.
Quote:Original post by mbanghart
Thanks. But this is for a school project and I have to use polygons. The cube is being displayed 2D (and I have to use 6 vertices) and my input data is 3D.
Triangles and Quads are Polygons. Polygon just means a "many-sides" ;)
Secondly it's impossible to have a "cube" in 3D with only 6 vertices. Think about it, or better yet pick up a box and count the number of corners, there are 8. Any less than 8 and you cannot have a cube.
It is possible to represent something that looks like a cube using 6 projected vertices (since 2 will always be culled as they will be back-facing) but I don't think thats what your homework means.
Andy
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement