This function changes the current color index to the one specified by c. This indexvalue
is maintained internally as a floating point number.
The new color index to use for all subsequent operations.
pointer to the new color index to use for all subsequent operations.
The following code from the sample program INDEX draws a smoothly shaded triangle. The top of the triangle is set to color index 0 which has been set to zero, and the bottom corners to color index 255 which has been set to bright red.
// Draw the triangle
// Darkest Red Apex (black)
// Brightest red bottom corners
glVertex3f(-200.0f, -70.0f, 0.0f);
Protects individual bits in the color index buffer from being set.
void glIndexMask(GLuint mask );
This function allows masking of individual bits
in the color index buffer. Where the mask bit is set, the bits are
writeable; where they are zero, they are write-protected from pixel
operations. This function only applies to color index mode.
GLuint: Specifies the binary bit mask to enable or disable writing to individual bits in the color index buffer.
See the sample program MASK on the CD for this chapter.
glIndex, glDepthMask, glStencilMask
Sets the logical pixel operation for color index mode.
void glLogicOp(GLenum opcode);
The logical pixel operation defines the combination of pixel values. When a new color index value is specified for a pixel location, it is combined logically with the current color index value for that pixel. To enable logical pixel operations, call glEnable(GL_LOGIC_OP), to disable call glDisable(GL_LOGIC_OP). When logical pixel operations are enabled, incoming pixel values are combined with existing pixel values in the manner specified by opcode. When logical operations are not
enabled, the net effect of pixel operations is as if GL_COPY were
specified. Logical pixel operations are not supported in RGBA color
GLEnum: Specifies the logical pixel mode to use. Any of the values listed in Table 8-2 are valid. This table lists the logical operation and the result of the operation, with s representing the source color index value, and d representing the destination color index value.
See the FLASHER example program from the CD. This example uses GL_XOR to produce smooth animation without double buffering.
glGet, glIsEnabled, glEnable, glDisable
Table 8-2 Valid Pixel Copy Operations
s & d
!(s & d)
s | d
!(s | d)
s ^ d
!(s ^ d)
s & !d
!s & d
s | !d
!s | d
Sets default shading to flat or smooth.
void glShadeModel(GLenum mode );
OpenGL primitives are always shaded, but the
shading model may be flat (GL_FLAT) or smooth (GL_SMOOTH). In the
simplest of scenarios, one color is set with glColor() before a
primitive is drawn. This primitive is solid and flat (does not vary)
throughout, regardless of the shading. If a different color is
specified for each vertex, then the resulting image will vary with the
shading model. With smooth shading, the color of the polygonís interior
points are interpolated from the colors specified at the vertices. This
means the color will vary from one color to the next between two
vertices. The color variation follows a line through the color cube
between the two colors. If lighting is enabled, OpenGL will do other
calculations to determine the correct colors (see Chapter 9). In flat
shading, the color specified for the last vertex is used throughout the
region of the primitive. The only exception is for GL_POLYGON, in which
case the color used throughout the region is the one specified for the
Specifies the shading model to use, either GL_FLAT or GL_SMOOTH. The default is GL_SMOOTH.
See the TRIANGLE and CCUBE examples from Chapter 8ís subdirectory on the CD.