gl.Light(light, pname, param)
gl.Light()
sets the values of individual light source parameters. light
names the light and is a symbolic name of the form #GL_LIGHTi
,
where i
ranges from 0 to the value of #GL_MAX_LIGHTS
- 1. pname
specifies one of ten light source parameters, again by symbolic name.
param
is either a single floating-point value or a table that contains several floating-point values. This depends on the pname
parameter.
To enable and disable lighting calculation, call gl.Enable() and gl.Disable() with argument #GL_LIGHTING
.
Lighting is initially disabled. When it is enabled, light sources that are enabled contribute to the lighting calculation. Light source i
is enabled and disabled using gl.Enable() and gl.Disable() with argument #GL_LIGHTi
.
The ten light parameters are as follows:
#GL_AMBIENT
param
must contain four floating-point values that specify the ambient RGBA intensity of the light. The initial ambient light intensity is (0, 0, 0, 1).
#GL_DIFFUSE
param
must contain four floating-point values that specify the diffuse RGBA intensity of the light. The initial value for #GL_LIGHT0
is (1, 1, 1, 1); for other lights, the initial value is (0, 0, 0, 1).
#GL_SPECULAR
param
must contain four floating-point values that specify the specular RGBA intensity of the light. The initial value for #GL_LIGHT0
is (1, 1, 1, 1); for other lights, the initial value is (0, 0, 0, 1).
#GL_POSITION
param
must contain four floating-point values that specify the position of the light in homogeneous object coordinates. The position is transformed by the
modelview matrix when gl.Light()
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, the
light is treated as a directional source. Diffuse and specular lighting calculations take the light's direction, but not its actual position, into account,
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 initial position is (0, 0, 1, 0); thus, the initial light source is directional, parallel to, and in the direction of the -z axis.
#GL_SPOT_DIRECTION
param
must contain three floating-point values that specify the direction of the light in homogeneous object coordinates. The spot direction is transformed
by the upper 3x3 of the modelview matrix when gl.Light()
is called, and it is stored in eye coordinates. It is significant only when #GL_SPOT_CUTOFF
is not
180, which it is initially. The initial direction is (0, 0, -1).
#GL_SPOT_EXPONENT
param
must be a single floating-point value that specifies the intensity distribution of the light. 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 #GL_SPOT_CUTOFF
, next paragraph). The initial spot exponent is 0, resulting in uniform light distribution.
#GL_SPOT_CUTOFF
param
must be a single floating-point value that specifies the maximum spread angle of a light source. 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 initial spot cutoff is 180,
resulting in uniform light distribution.
#GL_CONSTANT_ATTENUATION
param
must be a single floating-point value that specifies one of the three light attenuation factors. Only non-negative 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 initial attenuation factors are (1, 0, 0),
resulting in no attenuation.
#GL_LINEAR_ATTENUATION
#GL_CONSTANT_ATTENUATION
above.
#GL_QUADRATIC_ATTENUATION
#GL_CONSTANT_ATTENUATION
above.
It is always the case that #GL_LIGHTi
= #GL_LIGHT0
+ i.
Please consult an OpenGL reference manual for more information.
pname
parameter, see above)#GL_INVALID_ENUM
is generated if either light
or pname
is not an accepted value.
#GL_INVALID_VALUE
is generated if a spot exponent value is specified outside the range (0, 128) , or if spot cutoff is specified outside the
range (0, 90) (except for the special value 180), or if a negative attenuation factor is specified.
#GL_INVALID_OPERATION
is generated if gl.Light()
is executed between the execution of gl.Begin() and the corresponding execution of gl.End().
gl.IsEnabled() with argument #GL_LIGHTING