# 3D Cube

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

## Recommended Posts

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

##### Share on other sites
A 3D Cube has 8 Vertices last time I checked.

##### Share on other sites
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.

##### Share on other sites
Quote:
 Original post by mbanghartHi,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?

GL_Polygon

##### Share on other sites
First off don't use GL_POLYGON ever, and you need glBegin() and glEnd() when you draw polygons in immediate mode.

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.

##### Share on other sites
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.

##### Share on other sites
Quote:
 Original post by mbanghartThanks. 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

1. 1
Rutin
42
2. 2
3. 3
4. 4
5. 5

• 9
• 27
• 20
• 14
• 14
• ### Forum Statistics

• Total Topics
633387
• Total Posts
3011608
• ### Who's Online (See full list)

There are no registered users currently online

×