[ Previous | Next | Contents | Glossary | Home | Search ]
OpenGL 1.1 for AIX: Reference Manual

glLight Subroutine

Purpose

Sets light source parameters.

Library

OpenGL C bindings library: libGL.a

C Syntax

void glLightf(GLenum Light,
   GLenum ParameterName, 
   GLfloat Parameter)
void glLighti(GLenum Light,
   GLenum ParameterName, 
   GLint Parameter)
void glLightfv(GLenum Light,
   GLenum ParameterName, 
   const GLfloat *ParameterValues)
void glLightiv(GLenum Light,
   GLenum ParameterName, 
   const GLint *ParameterValues)

Parameters

Light Specifies a light. The number of lights depends on the implementation, but at least eight lights are supported. They are identified by symbolic names of the form GL_LIGHTi where 0 is less than or equal to i which is less than GL_MAX_LIGHTS.
ParameterName For glLightf, glLighti, and glLightv, this parameter specifies a single-valued light source parameter for Light. GL_SPOT_EXPONENT, GL_SPOT_CUTOFF, GL_CONSTANT_ATTENUATION, GL_LINEAR_ATTENUATION, and GL_QUADRATIC_ATTENUATION are accepted.

For glLightfv and glLightiv, this parameter specifies a light source parameter for Light. GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR, GL_POSITION, GL_SPOT_DIRECTION, GL_SPOT_EXPONENT, GL_SPOT_CUTOFF, GL_CONSTANT_ATTENUATION, GL_LINEAR_ATTENUATION, and GL_QUADRATIC_ATTENUATION are accepted.

Parameter Specifies the value to which the parameter ParameterName of light source Light is set.
ParameterValues Specifies a pointer to the value or values to which the parameter ParameterName of light source Light is set. This parameter is used only with glLightfv and glLightiv.

Description

The glLight subroutine sets the values of individual light source parameters. Light names the light and is a symbolic name of the form GL_LIGHTi, where 0 is less than or equal to i which is less than GL_MAX_LIGHTS. ParameterName specifies one of 10 light source parameters, again by symbolic name. ParameterValues is either a single value or a pointer to an array that contains the new values.

Lighting calculation is enabled and disabled using glEnable and glDisable with argument GL_LIGHTING. When lighting is enabled, light sources that are enabled contribute to the lighting calculation. Light source i is enabled and disabled using glEnable and glDisable with argument GL_LIGHTi.

The 10 light parameters are as follows:

GL_AMBIENT ParameterValues contains four integer or floating-point values that specify the ambient red, green, blue, alpha (RGBA) intensity of the light. Integer values are mapped linearly such that the most positive representable value maps to 1.0, and the most negative representable value maps to -1.0. Floating-point values are mapped directly. Neither integer nor floating-point values are clamped. The default ambient light intensity is (0.0, 0.0, 0.0, 1.0).
GL_DIFFUSE ParameterValues contains four integer or floating-point values that specify the diffuse RGBA intensity of the light. Integer values are mapped linearly such that the most positive representable value maps to 1.0, and the most negative representable value maps to -1.0. Floating-point values are mapped directly. Neither integer nor floating-point values are clamped. The default diffuse intensity is (0.0, 0.0, 0.0, 1.0) for all lights other than light zero. The default diffuse intensity of light zero is (1.0, 1.0, 1.0, 1.0).
GL_SPECULAR ParameterValues contains four integer or floating-point values that specify the specular RGBA intensity of the light. Integer values are mapped linearly such that the most positive representable value maps to 1.0, and the most negative representable value maps to -1.0. Floating-point values are mapped directly. Neither integer nor floating-point values are clamped. The default specular intensity is (0.0, 0.0, 0.0, 1.0) for all lights other than light zero. The default specular intensity of light zero is (1.0, 1.0, 1.0, 1.0).
GL_POSITION ParameterValues contains four integer or floating-point values that specify the position of the light in homogeneous object coordinates. Both integer and floating-point values are mapped directly. Neither integer nor floating-point values are clamped.

The position is transformed by the modelview matrix when glLight is called (just as if it were a point), and it is stored in eye coordinates. If the w component of the position is 0.0, the light is treated as a directional source. Diffuse and specular lighting calculations consider the light's direction, but not its actual position, and attenuation is disabled. Otherwise, diffuse and specular lighting calculations are based on the actual location of the light in eye coordinates, and attenuation is enabled. The default position is (0,0,1,0); thus, the default light source is directional, as well as parallel to and in the direction of the -z axis.

GL_SPOT_DIRECTION ParameterValues contains three integer or floating-point values that specify the direction of the light in homogeneous object coordinates. Both integer and floating-point values are mapped directly. Neither integer nor floating-point values are clamped.

The spot direction is transformed by the inverse of the modelview matrix when glLight is called (just as if it were a normal), and it is stored in eye coordinates. It is significant only when GL_SPOT_CUTOFF is not 180, which it is by default. The default direction is (0,0,-1).

GL_SPOT_EXPONENT ParameterValues is a single integer or floating-point value that specifies the intensity distribution of the light. Integer and floating-point values are mapped directly. Only values in the range [0,128] are accepted.

Effective light intensity is attenuated by the cosine of the angle between the direction of the light and the direction from the light to the vertex being lighted, raised to the power of the spot exponent. Thus, higher spot exponents result in a more focused light source, regardless of the spot cutoff angle. (See the GL_SPOT_CUTOFF description.) The default spot exponent is 0, resulting in uniform light distribution.

GL_SPOT_CUTOFF ParameterValues is a single integer or floating-point value that specifies the maximum spread angle of a light source. Integer and floating-point values are mapped directly. Only values in the range [0,90] and the special value 180 are accepted. If the angle between the direction of the light and the direction from the light to the vertex being lighted is greater than the spot cutoff angle, the light is completely masked. Otherwise, its intensity is controlled by the spot exponent and the attenuation factors. The default spot cutoff is 180, resulting in uniform light distribution.
GL_CONSTANT_ATTENUATION, GL_LINEAR_ATTENUATION, or GL_QUADRATIC_ATTENUATION
                          ParameterValues is a single integer or floating-point value that specifies one of the three light attenuation factors. Integer and floating-point values are mapped directly. Only nonnegative values are accepted. If the light is positional, rather than directional, its intensity is attenuated by the reciprocal of the sum of the constant factor, the linear factor times the distance between the light and the vertex being lighted, and the quadratic factor times the square of the same distance. The default attenuation factors are (1,0,0), resulting in no attenuation.

Notes

It is always the case that GL_LIGHTi = GL_LIGHT0 + i.

Errors

GL_INVALID_ENUM Either Light or ParameterName is not an accepted value.
GL_INVALID_VALUE A spot exponent value is specified outside the range [0,128], or spot cutoff is specified outside the range [0,90] (except for the special value 180), or a negative attenuation factor is specified.
GL_INVALID_OPERATION The glLight subroutine is called between a call to glBegin and the corresponding call to glEnd.

Associated Gets

Associated gets for the glLight subroutine are as follows. (See the glGet subroutine for more information.)

glGetLight

glIsEnabled with argument GL_LIGHTING.

Files

/usr/include/GL/gl.h Contains C language constants, variable type definitions, and ANSI function prototypes for OpenGL.

Related Information

The glBegin or glEnd subroutine, glColorMaterial subroutine, glEnable or glDisable subroutine, glLightModel subroutine, glMaterial subroutine.

OpenGL Overview.


[ Previous | Next | Contents | Glossary | Home | Search ]