# 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 on other sites
I believe glIndexPointer might be what you're after.

##### Share on other sites
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 on other sites
The easy way would be to just create 4 vertices (of the same color) for each face.

- Andrew

##### 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...

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628320
• Total Posts
2982055

• 11
• 9
• 9
• 13
• 11