glLight

Definition: include pGUI.e
include opengl.e

glLight(integer light, integer pname, object params)
Description: The glLight function sets the light source parameter values.

light: The identifier of a light. The number of possible lights depends on the implementation, but at least eight lights are supported.
They are identified by symbolic names of the form GL_LIGHTi where i is a value: 0 to GL_MAX_LIGHTS - 1.

pname: A light source parameter for light. See the Remarks section for possible values.

params: Specifies the value or values that parameter pname of light source light will be set to.

If light or pname was not an accepted value, glGetError() will return GL_INVALID_ENUM.
If a spot exponent value was specified outside the range [0, 128], or spot cutoff was specified outside the range [0, 90] (except for the special value 180), or a negative attenuation factor was specified, glGetError() will return GL_INVALID_VALUE.
If glLight is called between glBegin and glEnd, glGetError() will return GL_INVALID_OPERATION.

Internally, glLight() invokes the C function glLightf when params is an atom, and glLightfv when params is a sequence.
It does not validate whether params is an atom or sequence of the correct length against the setting of pname.
The C functions glLighti and glLightiv are not wrapped, since params can be an integer, a float, a sequence of integer, a sequence of float, or even a sequence containing a mixture of integer and float. Obviously testing whether it is safe to invoke the int functions would be far more expensive than just always using the float versions, that is as far as opengl.e is concerned.
Some care may be necessary when translating C code, to ensure that params is not a memory address.
All four C functions just mentioned are syntax coloured illegal, and should be changed to a plain glLight after any required changes to the final "params" parameter setting.
Remarks The glLight function sets the value or values of individual light source parameters.

The light parameter names the light and is a symbolic name of the form GL_LIGHTi, where 0 <= i < GL_MAX_LIGHTS.

The pname parameter specifies one of the light source parameters, again by symbolic name (as defined in opengl.e):

Value Meaning
GL_AMBIENT The params parameter contains four floating-point values that specify the ambient RGBA intensity of the light.
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 The params parameter contains four floating-point values that specify the diffuse RGBA intensity of the light.
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 The params parameter contains four floating-point values that specify the specular RGBA intensity of the light.
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 The params parameter contains four 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 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 default position is (0,0,1,0); thus, the default light source is directional, parallel to, and in the direction of the -z axis.
GL_SPOT_DIRECTION The params parameter contains three 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 The params parameter is a single 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.
The default spot exponent is 0, resulting in uniform light distribution.
GL_SPOT_CUTOFF The params parameter is a single 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, then 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,
GL_QUADRATIC_ATTENUATION
The params parameter is a single 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 multiplied by the distance between the light and the vertex being lighted, and
the quadratic factor multiplied by the square of the same distance.
The default attenuation factors are (1,0,0), resulting in no attenuation.


The params parameter is either a single value or a sequence 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.

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

The following functions retrieve information related to the glLight function:
glGetLight
glIsEnabled with argument GL_LIGHTING
See Also: glBegin, glEnd, xor_bits, glGetError, not_bits, int_to_bits
DEV See also //glBegin glColorMaterial //glEnd glLightModel glMaterial