PDA

View Full Version : The best way to draw a cube

mjriggio
11-17-2002, 02:57 PM
I'm new to openGL and am have been successful at drawing a cube http://www.opengl.org/discussion_boards/ubb/smile.gif However, I'm concerned about the efficiency of which I drew the cube. Currently, this is what I'm doing:

I'm using vertex arrays, and filling it with 24 vertices (4 for each face). I was kinda hoping I would be able to just specify 8 vertices total, and then have it just figure it out itself... http://www.opengl.org/discussion_boards/ubb/smile.gif Is this possible? If so, can someone provide an example for me to work from?

Also, I'm not sure if this matters, but I do plan on using lighting in my program, so I'm not sure if this throws off any possible solutions.

Finally, I was reading somewhere that it would be better to store it as a set of triangles instead of rectangles. Is this the case?

TIA,
-Mike

nexusone
11-17-2002, 04:46 PM
First you can make a routine that only takes 8 vertex points and makes a cube, but in the routine you will still have to have 24 vertex defined for the cube to be drawn.

I think Triangles are processed somewhat faster, then quads when using hardware.

As for lighting,

Originally posted by mjriggio:
I'm new to openGL and am have been successful at drawing a cube http://www.opengl.org/discussion_boards/ubb/smile.gif However, I'm concerned about the efficiency of which I drew the cube. Currently, this is what I'm doing:

I'm using vertex arrays, and filling it with 24 vertices (4 for each face). I was kinda hoping I would be able to just specify 8 vertices total, and then have it just figure it out itself... http://www.opengl.org/discussion_boards/ubb/smile.gif Is this possible? If so, can someone provide an example for me to work from?

Also, I'm not sure if this matters, but I do plan on using lighting in my program, so I'm not sure if this throws off any possible solutions.

Finally, I was reading somewhere that it would be better to store it as a set of triangles instead of rectangles. Is this the case?

TIA,
-Mike

ImpactDNI
11-17-2002, 05:24 PM
I Had this same thought when i started opengl... Heres 2 good ideas
#1, use the cube function, opengl has a built in cube drawing function =P
#2, use 2 matricies.
static float vertex[8][3] = {{x,y,z}, {x,y,z}, {x,y,z}, {x,y,z}, {x,y,z}, {x,y,z}, {x,y,z}, {x,y,z}};
// that is where you put your 8 verticies
static float link[6][4] = {0,1,2,3}, {4,5,6,7}, {0,1,5,4}, {1,2,6,5}, {2,3,7,6}, {3,0,7,4}};
// those are the order in which the verticies are linked
now draw each of of those quads