Sign in to follow this  
uridicy

vertex arrays

Recommended Posts

I'm using vertex arrays to create a cube. I've used the GL_VERTEX_ARRAY and the GL_COLOR_ARRAY to draw and color the cube. However, using these arrays only lets me set an individual color to each VERTEX. I need to set an individual color to each FACE. Does anyone know how to do this? Here's some of the code that I'm using so you'll have a better idea what I'm doing: This is how I enabled the arrays:
   glEnableClientState(GL_COLOR_ARRAY);
   glEnableClientState(GL_VERTEX_ARRAY);

   glVertexPointer(3, GL_FLOAT, 0, cubeVertices);
   glColorPointer(3, GL_FLOAT, 0, cubeColors);
Here are the arrays I created:
GLfloat cubeVertices[] ={-5,-5,-5, 5,-5,-5,
5,5,-5, -5,5,-5, -5,-5,5, 5,
-5,5, 5,5,5, -5,5,5};

GLfloat cubeColors[] = {0,0,0, 1,0,0, 1,1,0,
0,1,0, 0,0,1, 1,0,1, 1,1,1, 0,1,1};

GLubyte cubeIndices[]={0,3,2,1, 2,3,7,6, 0,4,7,3, 1,2,6,5, 4,5,6,7, 0,1,5,4};
Here's where I drew the cube: [cube] glDrawElements(GL_QUADS, 24, GL_UNSIGNED_BYTE, cubeIndices); [/cube]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Um, no. glIndexPointer is for Color Index mode (array version of immediate mode function glIndexi, etc.).

OpenGL is a little strange when it comes to per face color (instead of per vertex color).

Typically, using immediate mode, per face color will be as follows:

glBegin(GL_TRIANGLES);
for (i = 0; i <

Share this post


Link to post
Share on other sites
Yes, the only way is to create 4 vertices per side and set the corresponding color entries to the color that you want. It seems counter-intuitive, but this is the only way...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this