Graphics Reference
In-Depth Information
Then we can draw the RGB cube using the glArrayElement( ) function
and simply list all the vertices by their index. The geometry and color for each
vertex is used as if the glVertex( ) and glColor( ) statements were given for
each vertex.
glEnableClientState( GL_VERTEX_ARRAY );
glEnableClientState( GL_COLOR_ARRAY );
glVertexPointer( 3, GL_FLOAT, 0, CubeVertices );
glColorPointer( 3, GL_FLOAT, 0, CubeColors );
glBegin( GL_QUADS );
glArrayElement( 0 );
glArrayElement( 2 );
glArrayElement( 3 );
glArrayElement( 1 );
glArrayElement( 4 );
glArrayElement( 5 );
glArrayElement( 7 );
glArrayElement( 6 );
glArrayElement( 1 );
glArrayElement( 3 );
glArrayElement( 7 );
glArrayElement( 5 );
glArrayElement( 0 );
glArrayElement( 4 );
glArrayElement( 6 );
glArrayElement( 2 );
glArrayElement( 2 );
glArrayElement( 6 );
glArrayElement( 7 );
glArrayElement( 3 );
glArrayElement( 0 );
glArrayElement( 1 );
glArrayElement( 5 );
glArrayElement( 4 );
glEnd( );
This feels rather long and inelegant, and not very productive. But we
can also define an array that holds the indices of the vertices on each of the six
faces of the cube and use the glDrawElements( ) function.
static GLuint CubeIndices[ ][4] =
{
{ 0, 2, 3, 1 },
{ 4, 5, 7, 6 },
{ 1, 3, 7, 5 },
{ 0, 4, 6, 2 },
{ 2, 6, 7, 3 },
{ 0, 1, 5, 4 }
};
Search WWH ::




Custom Search