This chapter covers one of the most important features supported by a graphics package: color. You have seen how to specify a color in terms of its RGB components, and how these components relate to one another in the RGB color cube. Your understanding of glColor has been expanded to include the coloring of vertices, and you have seen how this affects shading. We explained OpenGLís selection of colors in 4-, 8-, 16-, and 24-bit Windows color modes. We demonstrated the building of a 3-3-2 palette for use by OpenGL in 8-bit color modes. Finally, we took a brief look at color index mode and its utilization to gain better palette control in 8-bit color modes.
Good use of color and shading is a prerequisite for good 3D graphics. The upcoming chapter explains how OpenGL uses shading to produce lighting effects. Youíll learn how to specify material colors and lighting conditions and allow OpenGL to select the drawing colors.
Sets the clear value for the color index buffers.
void glClearIndex(GLfloat color);
This function specifies the color index to use in color index mode to clear the color buffers. This has the net effect of clearing the window and setting the background color to the color in the index specified by the color parameter.
GLfloat: The value to use when the color index buffers are cleared with glClear. The default is 0.
This function sets the current color by
specifying separate red, green, and blue components of the color. Some
functions also accept an alpha component. Each component represents the
range of intensity from zero (0.0) to full intensity (1.0).
Functions with the v suffix take a
pointer to an array that specifies the components. Each element in the
array must be of the same type. When the alpha component is not
specified, it is implicitly set to 1.0. When non-floating point types
are specified, the range from zero to the largest value represented by
that type is mapped to the floating point range 0.0 to 1.0.
Specifies the red component of the color.
Specifies the green component of the color.
Specifies the blue component of the color.
Specifies the alpha component of the color. Used only in variations that take four arguments.
A pointer to an array of red, green, blue, and possibly alpha values.
The following code from the CCUBE example in this chapter sets one of the corners of the color cube to white.
// Front face
glColor3ub((GLubyte) 255, (GLubyte)255, (GLubyte)255);
Enables or disables modification of color components in the color buffers.
This function allows changes to individual
color components in the color buffer to be disabled or enabled (all are
enabled by default). For example, setting the bAlpha argument to
GL_FALSE disallows changes to the alpha color component.
GLboolean: Specifies whether the red component may be modified.
GLboolean: Specifies whether the green component may be modified.
GLboolean: Specifies whether the blue component may be modified.
GLboolean: Specifies whether the alpha component may be modified.
See the sample program MASK on the CD for this chapter.