# glLight

set light source parameters

## Signature

glLight( )->
glLight( )
glLightf( GLenum ( light ) , GLenum ( pname ) , GLfloat ( param ) )-> void
glLightf( )
glLightfv( GLenum ( light ) , GLenum ( pname ) , const GLfloat * ( params ) )-> void
glLightfv( )
glLighti( GLenum ( light ) , GLenum ( pname ) , GLint ( param ) )-> void
glLighti( )
glLightiv( GLenum ( light ) , GLenum ( pname ) , const GLint * ( params ) )-> void
glLightiv( )

## Parameters

VariablesDescription
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_LIGHT $\mathit{i}$ , where i ranges from 0 to the value of GL_MAX_LIGHTS - 1.
pname
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.
param
Specifies the value that parameter pname of light source light will be set to.

## 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_LIGHT $\mathit{i}$ , where i ranges from 0 to the value of GL_MAX_LIGHTS - 1.
pname
Specifies a light source parameter for light . GL_AMBIENT , GL_DIFFUSE , GL_SPECULAR , GL_POSITION , GL_SPOT_CUTOFF , GL_SPOT_DIRECTION , GL_SPOT_EXPONENT , GL_CONSTANT_ATTENUATION , GL_LINEAR_ATTENUATION , and GL_QUADRATIC_ATTENUATION are accepted.
params
Specifies a pointer to the value or values that parameter pname of light source light will be set to.

## Description

glLight sets the values of individual light source parameters. light names the light and is a symbolic name of the form GL_LIGHT $\mathit{i}$ , 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. params is either a single value or a pointer to an array that contains the new values.
To enable and disable lighting calculation, call glEnable and glDisable with argument GL_LIGHTING . Lighting is initially disabled. When it is enabled, light sources that are enabled contribute to the lighting calculation. Light source $\mathit{i}$ is enabled and disabled using glEnable and glDisable with argument GL_LIGHT $\mathit{i}$ .
The ten light parameters are as follows:
GL_AMBIENT
params contains four integer or floating-point values that specify the ambient 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 initial ambient light intensity is (0, 0, 0, 1).
GL_DIFFUSE
params 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 initial value for GL_LIGHT0 is (1, 1, 1, 1); for other lights, the initial value is (0, 0, 0, 1).
GL_SPECULAR
params 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 initial value for GL_LIGHT0 is (1, 1, 1, 1); for other lights, the initial value is (0, 0, 0, 1).
GL_POSITION
params 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 $\mathit{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 $-\mathit{z}$ axis.
GL_SPOT_DIRECTION
params 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 upper 3x3 of the modelview matrix when glLight 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 $\left(0,0,-1\right)$ .
GL_SPOT_EXPONENT
params 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 $\left[0,128\right]$ 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
params 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 $\left[0,90\right]$ 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
GL_LINEAR_ATTENUATION
params 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 initial attenuation factors are (1, 0, 0), resulting in no attenuation.

## Notes

It is always the case that GL_LIGHT $\mathit{i}$ = GL_LIGHT0 + $\mathit{i}$ .

## Errors

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 $\left[0,128\right]$ , or if spot cutoff is specified outside the range $\left[0,90\right]$ (except for the special value 180), or if a negative attenuation factor is specified.
GL_INVALID_OPERATION is generated if glLight is executed between the execution of glBegin and the corresponding execution of glEnd .

## Associated Gets

glIsEnabled with argument GL_LIGHTING

## Sample Code References

The following code samples have been found which appear to reference the functions described here. Take care that the code may be old, broken or not even use PyOpenGL.

glLight
OpenGLContext OpenGLContext/passes/rendervisitor.py Lines: 188, 189
{GPL3} OpenGL-Programmable 07-attrib.py Lines: 347
{GPL3} OpenGL-Programmable 06-perpixel.py Lines: 336
{GPL3} OpenGL-Programmable 08-pbo.py Lines: 369
{GPL3} OpenGL-Programmable 01-direct.py Lines: 239
{GPL3} OpenGL-Programmable 02-displaylist.py Lines: 248
{GPL3} OpenGL-Programmable 04-vbo.py Lines: 269
{GPL3} OpenGL-Programmable 03-array.py Lines: 250
{GPL3} OpenGL-Programmable 05-shader.py Lines: 328
glLightf
OpenGLContext OpenGLContext/scenegraph/light.py Lines: 123, 124, 125, 160, 162
glLightfv
OpenGLContext tests/nehe8.py Lines: 67, 68, 69
OpenGLContext tests/redbook_alpha3D.py Lines: 119
OpenGLContext tests/nehe7.py Lines: 76, 77, 78
OpenGLContext OpenGLContext/scenegraph/light.py Lines: 54, 60, 69, 159
OpenGL-Demo PyOpenGL-Demo/redbook/movelight.py Lines: 98
OpenGL-Demo PyOpenGL-Demo/redbook/fog.py Lines: 74
OpenGL-Demo PyOpenGL-Demo/redbook/teapots.py Lines: 74, 75, 76
OpenGL-Demo PyOpenGL-Demo/redbook/scene.py Lines: 72, 73, 74, 75
OpenGL-Demo PyOpenGL-Demo/GLUT/gears.py Lines: 225
OpenGL-Demo PyOpenGL-Demo/GLUT/tom/text.py Lines: 34, 35, 36, 37
OpenGL-Demo PyOpenGL-Demo/GLUT/tom/cone.py Lines: 39, 40, 41, 42
OpenGL-Demo PyOpenGL-Demo/GLUT/tom/checker.py Lines: 78, 79
OpenGL-Demo PyOpenGL-Demo/proesch/nurbs/nurbs.py Lines: 172, 173, 174, 175
OpenGL-Demo PyOpenGL-Demo/proesch/stereo/stereoDemo.py Lines: 48, 49, 50, 110, 112, 114, 116
OpenGL-Demo PyOpenGL-Demo/proesch/bezier/bezier.py Lines: 121, 122, 123, 124
OpenGL-Demo PyOpenGL-Demo/GLE/maintest.py Lines: 57, 58, 60, 61
OpenGL-Demo PyOpenGL-Demo/tom/conechecker.py Lines: 38, 39, 40, 41
OpenGL-Demo PyOpenGL-Demo/tom/fog.py Lines: 44
OpenGL-Demo PyOpenGL-Demo/tom/cone.py Lines: 17, 18, 19, 20
OpenGL-Demo PyOpenGL-Demo/tom/conesave.py Lines: 21, 22, 23, 24
OpenGL-Demo PyOpenGL-Demo/NeHe/lesson18.py Lines: 121, 122, 123
OpenGL-Demo PyOpenGL-Demo/NeHe/lesson26.py Lines: 63, 64, 65, 166, 177
Glinter Core.py Lines: 211, 213, 215, 217
{Artistic License} PymmLib applications/glutviewer.py Lines: 196, 197, 198, 200
{Artistic License} PymmLib mmLib/OpenGLDriver.py Lines: 171, 172, 173, 174
{LGPL} PyMT pymt/obj.py Lines: 22, 277, 278
{GPL} GLChess src/lib/scene/opengl/opengl.py Lines: 351, 352, 353, 371
{LGPL} Pyggel pyggel/light.py Lines: 39, 40, 41, 42, 43
{LGPL or GPL or MPL} Kamaelia Sketches/CL/Topology3D/Experiments/Spheres.py Lines: 52, 53, 54, 55
{LGPL or GPL or MPL} Kamaelia Sketches/CL/Topology3D/Experiments/Cubes.py Lines: 71, 72, 73
Visvis core/light.py Lines: 265, 268, 269, 270, 273