Sign in to follow this  
Daniel Lee


Recommended Posts

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.

Share this post

Link to post
Share on other sites
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.

glBegin( GL_QUADS );
for( int i=0; i<6; i++ )
glColor3fv( &colors[i].x );
glVertex3fv( &corners[ indexes[i][0] ].x );
glVertex3fv( &corners[ indexes[i][1] ].x );
glVertex3fv( &corners[ indexes[i][2] ].x );
glVertex3fv( &corners[ indexes[i][3] ].x );

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