Open GL Super Bible

Previous Table of Contents Next


Reference Section

glColorMaterial

Purpose
Allows material colors to track the current color as set by glColor.
Include File
<gl.h>
Syntax
void glColorMaterial(GLenum face, GLenum mode);
Description
This function allows material properties to be set without having to call glMaterial directly. By using this function, certain material properties can be set to follow the current color as specified by glColor. By default, color tracking is disabled; to enable it, you must also call glEnable(GL_COLOR_MATERIAL). To disable color tracking again, call glDisable(GL_COLOR_MATERIAL).

Parameters

face
GLenum: Specifies if the front (GL_FRONT), back (GL_BACK), or both (GL_FRONT_AND_BACK) should follow the current color.
mode
GLenum: Specifies which material property should be following the current color. This can be GL_EMISSION, GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR, or GL_AMBIENT_AND_DIFFUSE.
Returns
None.

Example

The following code from the AMBIENT example program enables color tracking, then sets the front material parameters for ambient and diffuse reflectivity to follow the colors specified by glColor.

    glEnable(GL_COLOR_MATERIAL);  // Enable Material color tracking

    // Front material ambient and diffuse colors track glColor
    glColorMaterial(GL_FRONT,GL_AMBIENT_AND_DIFFUSE);
See Also
glColor, glMaterial, glLight, glLightModel

glCullFace

Purpose
Specifies whether the front or back of polygons should be eliminated from drawing.
Include File
<gl.h>
Syntax
void glCullFace(GLenum mode);
Description
This function disables lighting, shading, and color calculations and operations on either the front or back of a polygon. If, for instance, an object is closed in so that the back side of the polygons will never be visible regardless of rotation or translation, this will eliminate unnecessary computations in the display of the scene. Culling is enabled or disabled by calling glEnable and glDisable with the GL_CULL_FACE parameter. The front and back of the polygon are defined by use of the glFrontFace function and the order in which the vertices are specified (clockwise or counterclockwise winding).

Parameters

mode
GLenum: Specifies which face of polygons should be culled. May be either GL_FRONT, or GL_BACK.
Returns
None.

Example

The following code from the AMBIENT example from this chapter shows how the color and drawing operations are disabled for the inside of the jet. It is also necessary to indicate which side of the polygon is the outside by specifying clockwise or counterclockwise winding.

    glEnable(GL_CULL_FACE);  // Do not calculate inside of jet
    glFrontFace(GL_CCW);     // Counterclockwise polygons face out
See Also
glFrontFace, glLightModel

glFrontFace

Purpose
Defines which side of a polygon is the front or back.
Include File
<gl.h>
Syntax
void glFrontFace(GLenum mode);
Description
When a scene is made up of objects that are closed (you cannot see the inside), there is no need to do color or lighting calculations on the inside of the object. The glCullFace function will turn off such calculations for either the front or back of polygons. The glFrontFace function determines which side of the polygons is considered the front. If the vertices of a polygon are specified such that they travel around the polygon in a clockwise fashion, the polygon is said to have clockwise winding. If the vertices travel counterclockwise, the polygon is said to have counterclockwise winding. This function allows either the clockwise or counterclockwise wound face to be considered the front of the polygon.

Parameters

mode
GLenum: Specifies the orientation of front facing polygons, clockwise (GL_CW) or counterclockwise (GL_CCW).
Returns
None.

Example

The following code from the AMBEINT example from this chapter shows how the color and drawing operations are disabled for the inside of the jet. It is also necessary to indicate which side of the polygon is the outside by specifying clockwise or counterclockwise winding.

    glEnable(GL_CULL_FACE);  // Do not calculate inside of jet
    glFrontFace(GL_CCW);     // Counterclockwise polygons face out
See Also
glCullFace, glLightModel

glGetMaterial

Purpose
Returns the current material property settings.
Include File
<gl.h>
Variations
void glGetMaterialfv(GLenum face, GLenum pname, GLfloat *params);
void glGetMaterialiv(GLenum face, GLenum pname, GLint *params);
Description
Use this function to query the current front or back material properties. The return values are stored at the address pointed to by params. For most properties this is an array of four values containing the RGBA components of the property specified.

Parameters

face
GLenum: Specifies whether the front (GL_FRONT), or back (GL_BACK) material properties are being sought.
pname
GLenum: Specifies which material property is being queried. Valid values are: GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR, GL_EMISSION, GL_SHININESS, and GL_COLOR_INDEXES.
params
GLint* or GLfloat*: An array of integer or floating point values representing the return values. For GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR, and GL_EMISSION this is a four-element array containing the RGBA values of the property specified. For GL_SHININESS a single value representing the specular exponent of the material is returned. GL_COLOR_INDEXES returns an array of three elements containing the ambient, diffuse, and specular components in the form of color indexes. GL_COLOR_INDEXES is only used for color index lighting.
Returns
None.

Example

The following code shows how all the current material properties are read and stored.

    // Storage for all the material properties
    GLfloat mbientMat[4],diffuseMat[4],specularMat[4],emissionMat[4];
    GLfloat shine;
    
    
    // Read all the material properties
    glGetMaterialfv(GL_FRONT,GL_AMBIENT,ambientMat);
    glGetMaterialfv(GL_FRONT,GL_DIFFUSE,diffuseMat);
    glGetMaterialfv(GL_FRONT,GL_SPECULAR,specularMat);
    glGetMaterialfv(GL_FRONT,GL_EMISSION,emissionMat);
    glGetMaterialfv(GL_FRONT,GL_SHININESS,&shine);
See Also
glMaterial


Previous Table of Contents Next