Name
gl.Material -- specify material parameters for the lighting model
Synopsis
gl.Material(face, pname, param)
Function
gl.Material() assigns values to material parameters. There are two matched sets of material parameters. One, the front-facing set, is used to shade points, lines, bitmaps, and all polygons (when two-sided lighting is disabled), or just front-facing polygons (when two-sided lighting is enabled). The other set, back-facing, is used to shade back-facing polygons only when two-sided lighting is enabled. See gl.LightModel for details concerning one- and two-sided lighting calculations.

gl.Material() takes three arguments. The first, face, specifies whether the #GL_FRONT materials, the #GL_BACK materials, or both #GL_FRONT_AND_BACK materials will be modified. The second, pname, specifies which of several parameters in one or both sets will be modified. The third, param, specifies what value or values will be assigned to the specified parameter. It can be single floating-point value or a table containing multiple floating-point values.

Material parameters are used in the lighting equation that is optionally applied to each vertex. The equation is discussed in the gl.LightModel() reference page. The parameters that can be specified using gl.Material(), and their interpretations by the lighting equation, are as follows:

#GL_AMBIENT
param must be a table containing four floating-point values that specify the ambient RGBA reflectance of the material. The initial ambient reflectance for both front- and back-facing materials is (0.2, 0.2, 0.2, 1.0).

#GL_DIFFUSE
param must be a table containing four floating-point values that specify the diffuse RGBA reflectance of the material. The initial diffuse reflectance for both front- and back-facing materials is (0.8, 0.8, 0.8, 1.0).

#GL_SPECULAR
param must be a table containing four floating-point values that specify the specular RGBA reflectance of the material. The initial specular reflectance for both front- and back-facing materials is (0, 0, 0, 1).

#GL_EMISSION
param must be a table containing four floating-point values that specify the RGBA emitted light intensity of the material. The initial emission intensity for both front- and back-facing materials is (0, 0, 0, 1).

#GL_SHININESS
param must be a single floating-point value that specifies the RGBA specular exponent of the material. Only values in the range (0,128) are accepted. The initial specular exponent for both front- and back-facing materials is 0.

#GL_AMBIENT_AND_DIFFUSE
Equivalent to calling gl.Material() twice with the same parameter values, once with #GL_AMBIENT and once with #GL_DIFFUSE.

#GL_COLOR_INDEXES
param must be a table containing three floating-point values specifying the color indices for ambient, diffuse, and specular lighting. These three values, and #GL_SHININESS, are the only material values used by the color index mode lighting equation. See gl.LightModel for a discussion of color index lighting.

The material parameters can be updated at any time. In particular, gl.Material() can be called between a call to gl.Begin() and the corresponding call to gl.End(). If only a single material parameter is to be changed per vertex, however, gl.ColorMaterial() is preferred over gl.Material() (See gl.ColorMaterial for details.).

While the ambient, diffuse, specular and emission material parameters all have alpha components, only the diffuse alpha component is used in the lighting computation.

Please consult an OpenGL reference manual for more information.

Inputs
face
specifies which face or faces are being updated; must be one of #GL_FRONT, #GL_BACK, or #GL_FRONT_AND_BACK
pname
specifies the material parameter of the face or faces that is being updated (see above)
param
a floating-point value (or a table containing multiple floating-point values) that pname will be set to
Errors
#GL_INVALID_ENUM is generated if either face or pname is not an accepted value.

#GL_INVALID_VALUE is generated if a specular exponent outside the range (0,128) is specified.

Associated gets
gl.GetMaterial()


Show TOC