colorArray

Started by
0 comments, last by silvermace 18 years, 11 months ago
allo, lets take the Cube for example but using vertex Arrays this time. GLfloat corners[] = {8 * 3 vertices}; GLfloat colors[] = {red, green, blue, yellow, cyan, white}; GLubyte indexes[] = { 0,1,2,4, /// Front Face 4,5,1,0, /// Top 3,2,6,7, /// Bottom 5,4,7,6, /// Back 1,5,6,2, /// Right 4,0,3,7 /// Left }; as there are only 6 Faces, I used 6 colors in the colors Array and and used glShadeModel(GL_FLAT); but the cube was rendered with only 4 colors namely red,blue,yellow,cyan and 2 other Faces are black. what was wrong ? your kind assistance please.
Advertisement
if you are using vertex arrays etc, the color values needs to be per-vertex, not per face. This would pose a problem for you, as you share verticies amoungst faces.

if you are using immediate mode (glBegin/glEnd) the color attribute, much like the rest of GL, is a state varaible.

eg:
glBegin( GL_QUADS );  for( int i=0; i<6; i++ )  {   glColor3fv( &colors.x );     glVertex3fv( &corners[ indexes[0] ].x );     glVertex3fv( &corners[ indexes[1] ].x );     glVertex3fv( &corners[ indexes[2] ].x );     glVertex3fv( &corners[ indexes[3] ].x );  }glEnd();
"I am a donut! Ask not how many tris/batch, but rather how many batches/frame!" -- Matthias Wloka & Richard Huddy, (GDC, DirectX 9 Performance)

http://www.silvermace.com/ -- My personal website

This topic is closed to new replies.

Advertisement