Next: Blending and Fog:
Up: OpenGL Quick Reference Guide
In OpenGL there may be up to 8 light sources (GL_LIGHT0 through
GL_LIGHT7). If lighting is enabled (see glEnable()) then
the shading of each object depends on which light sources are turned on
(enabled) and the materials and surface normals of each of the objects
in the scene. Note that when lighting is enabled, it is important that
each vertex be associated with a proper normal vector (by calling
glNormal*()) prior to generating the vertex.
- glShadeModel(GLenum mode):
The mode may be either GL_FLAT or GL_SMOOTH.
In flat shading every point on a polygon is shaded according to
its first vertex. In smooth shading the shading from each of
the various vertices is interpolated.
- glLightModelf(GLenum pname, GLfloat param):
- glLightModelfv(GLenum pname, const GLfloat *params):
Defines general lighting model parameters. The first version is
for defining scalar parameters, and the second is for vector
parameters. One important parameter is the global intensity of
ambient light (independent of any light sources). Its
pname is GL_LIGHT_MODEL_AMBIENT and params
is a pointer to an RGBA vector.
- glLightf(GLenum light, GLenum pname, GLfloat param):
- glLightfv(GLenum light, GLenum pname, const GLfloat *params):
Defines parameters for a single light source. The first version
is for defining scalar parameters, and the second is for vector
parameters. The first argument indicates which light source
this applies to. The argument pname gives one of the
properties to be assigned. These include the following:
By default, illumination intensity does not decrease, or attenuate,
with distance. In general, if d is the distance from the
light source to the object, and the light source is not a point
at infinity, then the intensity attenuation is given by
1/(a + bd + cd*d) where a, b, and c are
specified by the following parameters:
- GL_POSITION: (vector) (x,y,z,
w) of position of light
- GL_AMBIENT: (vector) RGBA of intensity of ambient light
- GL_DIFFUSE: (vector) RGBA of intensity of diffuse light
- GL_SPECULAR: (vector) RGBA of intensity of specular light
Normally light sources send light uniformly in all directions. To
define a spotlight, set the following parameters.
- GL_CONSTANT_ATTENUATION: (scalar) a-coefficient
- GL_LINEAR_ATTENUATION: (scalar) b-coefficient
- GL_QUADRATIC_ATTENUATION: (scalar) c-coefficient.
Note: In addition to defining these properties, each light
source must also be enabled. See glEnable().
- GL_SPOT_CUTOFF: (scalar) maximum spread angle of spotlight
- GL_SPOT_DIRECTION: (vector) (x,y,
z,w) direction of spotlight
- GL_SPOT_EXPONENT: (scalar) exponent of spotlight
- glMaterialf(GLenum face, GLenum pname, GLfloat param):
- glMaterialfv(GLenum face, GLenum pname, const GLfloat *params):
Defines surface material parameters for subsequently defined
The first version is for defining scalar parameters, and the
second is for vector parameters.
Polygonal objects in OpenGL have two sides. You can assign
properties either to the front, back, or both sides. (The front
side is the one from which the vertices appear in counterclockwise
order.) The first argument indicates the side. The possible
values are GL_FRONT, GL_BACK, and
GL_FRONT_AND_BACK. The second argument is the
specific property. Possbilities include:
- GL_EMISSION: (vector) RGBA of the emitted coefficients
- GL_AMBIENT: (vector) RGBA of the ambient coefficients
- GL_DIFFUSE: (vector) RGBA of the diffuse coefficients
- GL_SPECULAR: (vector) RGBA of the specular coefficients
- GL_SHININESS: (scalar) single number in the range [0,128]
that indicates degree of shininess.
Please report any errors or send comments to
Last updated: Sat, Feb 8, 2003.