Graphics Reference
In-Depth Information
glVertexPointer( size, type, stride, array );
glColorPointer( size, type, stride, array );
glNormalPointer( type, stride, array );
glSecondaryColorPointer( size, type, stride, array );
glTexCoordPointer( size, type, stride, array );
that let you specify that an array is to be used for vertex
coordinates, colors, normals, etc. Here,
size
is the dimen-
sion of a vertex and can be 2, 3, or 4;
type
can be any of
GL_SHORT
,
GL_INT
,
GL_FLOAT
, or
GL_DOUBLE;
and
array
is
the name of the corresponding data array. The variable
stride
is the byte offset between consecutive entries in the
array (0 means tightly packed) and is most easily set with
the
sizeof( )
function.
As an example, let's draw the standard RGB cube
whose vertices are indexed in Figure 1.11 by specifying its
vertex coordinates and vertex colors. We set vertex 0 to be
black, its adjacent vertices 1, 2, and 4 to be red, green, and
blue respectively, vertices 3, 6, and 5 to be yellow, cyan, and
magenta respectively, and vertex 7 to be black.
The following statements set up these arrays:
Figure 1.11.
A cube with vertices
numbered to match the RGB cube.
static GLfloat CubeVertices[ ][3] =
{
{ -1., -1., -1. },
{ 1., -1., -1. },
{ -1., 1., -1. },
{ 1., 1., -1. },
{ -1., -1., 1. },
{ 1., -1., 1. },
{ -1., 1., 1. },
{ 1., 1., 1. }
};
static GLfloat CubeColors[ ][3] =
{
{ 0., 0., 0. },
{ 1., 0., 0. },
{ 0., 1., 0. },
{ 1., 1., 0. },
{ 0., 0., 1. },
{ 1., 0., 1. },
{ 0., 1., 1. },
{ 1., 1., 1. },
};