Jump to content
  • Advertisement
Sign in to follow this  

vertex arrays

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

If you intended to correct an error in the post then please contact us.

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:

   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:

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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!