Open GL Super Bible

Previous Table of Contents Next


glIndex

Purpose
Sets the current color index to be used for color operations.
Include File
<gl.h>
Variations
void glIndexd(GLdouble c);
void glIndexf(GLfloat c);
void glIndexi(GLint c);
void glIndexs(GLshort c);
void glIndexdv(const GLdouble *c);
void glIndexfv(const GLfloat *c);
void glIndexiv(const GLint *c);
void glIndexsv(const GLshort *c);
Description
This function changes the current color index to the one specified by c. This indexvalue is maintained internally as a floating point number.

Parameters

c
The new color index to use for all subsequent operations.
*cA
pointer to the new color index to use for all subsequent operations.
Returns
None.

Example

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
     glBegin(GL_TRIANGLES);
             // Darkest Red Apex (black)
             glIndexi(0);
             glVertex3f(0.0f,200.0f,0.0f);

             // Brightest red bottom corners
             glIndexi(255);
             glVertex3f(200.0f,-70.0f,0.0f);
             glVertex3f(-200.0f, -70.0f, 0.0f);
     glEnd();
See Also
glColor

glIndexMask

Purpose
Protects individual bits in the color index buffer from being set.
Include File
<gl.h>
Syntax
void glIndexMask(GLuint mask );
Description
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.

Parameters

mask
GLuint: Specifies the binary bit mask to enable or disable writing to individual bits in the color index buffer.
Returns
None.
Example
See the sample program MASK on the CD for this chapter.
See Also
glIndex, glDepthMask, glStencilMask

glLogicOp

Purpose
Sets the logical pixel operation for color index mode.
Include File
<gl.h>
Syntax
void glLogicOp(GLenum opcode);
Description
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 mode.

Parameters

opcode
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.
Returns
None.
Example
See the FLASHER example program from the CD. This example uses GL_XOR to produce smooth animation without double buffering.
See Also
glGet, glIsEnabled, glEnable, glDisable
Table 8-2 Valid Pixel Copy Operations

Opcode% Resulting Value

GL_CLEAR 0
GL_SET 1
GL_COPY s
GL_COPY_INVERTED! !s
GL_NOOP d
GL_INVERT !d
GL_AND s & d
GL_NAND !(s & d)
GL_OR s | d
GL_NOR !(s | d)
GL_XOR s ^ d
GL_EQUIV !(s ^ d)
GL_AND_REVERSE s & !d
GL_AND_INVERTED !s & d
GL_OR_REVERSE s | !d
GL_OR_INVERTED !s | d

glShadeModel

Purpose
Sets default shading to flat or smooth.
Include File
<gl.h>
Syntax
void glShadeModel(GLenum mode );
Description
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 first vertex.

Parameters

mode
Specifies the shading model to use, either GL_FLAT or GL_SMOOTH. The default is GL_SMOOTH.
Returns
None.
Example
See the TRIANGLE and CCUBE examples from Chapter 8ís subdirectory on the CD.
See Also
glColor, glLight, glLightModel


Previous Table of Contents Next