GLLIGHT(3G)
๐ GLLIGHT ๐
okay bestie, we're in the 3G manual today, and this page is called GLLIGHT โ it's the one about lighting up your scene, literally. glLightf, glLighti, glLightfv, glLightiv. four little functions, one big glow-up. let's get into it ๐
โจ NAME โจ
glLightf, glLighti, glLightfv, glLightiv โ set light source parameters
๐ C SPECIFICATION ๐
void glLightf( GLenum light,
GLenum pname,
GLfloat param )
void glLighti( GLenum light,
GLenum pname,
GLint param )
๐ธ PARAMETERS ๐ธ
lightโ which light are we talking about, bestie? the number of lights depends on the implementation, but at least eight lights are supported, no cap. they're identified by symbolic names of the formGL_LIGHTiwhere 0 โค i <GL_MAX_LIGHTS.pnameโ names one single-valued light source parameter for light. the accepted ones areGL_SPOT_EXPONENT,GL_SPOT_CUTOFF,GL_CONSTANT_ATTENUATION,GL_LINEAR_ATTENUATION, andGL_QUADRATIC_ATTENUATION.paramโ the value that parameter pname of light source light will be set to. the actual number, the moment.
๐ C SPECIFICATION (the pointer girlies) ๐
void glLightfv( GLenum light,
GLenum pname,
const GLfloat *params )
void glLightiv( GLenum light,
GLenum pname,
const GLint *params )
๐ธ PARAMETERS ๐ธ
lightโ same deal, specifies a light. number of lights depends on the implementation, at least eight are supported, identified by symbolic names of the formGL_LIGHTiwhere 0 โค i <GL_MAX_LIGHTS.pnameโ specifies a light source parameter for light. accepted here:GL_AMBIENT,GL_DIFFUSE,GL_SPECULAR,GL_POSITION,GL_SPOT_CUTOFF,GL_SPOT_DIRECTION,GL_SPOT_EXPONENT,GL_CONSTANT_ATTENUATION,GL_LINEAR_ATTENUATION, andGL_QUADRATIC_ATTENUATION.paramsโ a pointer to the value or values that parameter pname of light source light will be set to. yes queen, we're passing addresses around, it's giving very much pointer energy.
๐ฆ DESCRIPTION ๐ฆ
glLight sets the values of individual light source parameters. light names the light and is a symbolic name of the form GL_LIGHTi, where 0 โค i < GL_MAX_LIGHTS. 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 turn lighting calculation on and off, call glEnable and glDisable with argument GL_LIGHTING. lighting is initially disabled โ it starts asleep, it needs to be woken up. once it's enabled, the light sources that are enabled contribute to the lighting calculation. light source i gets enabled and disabled using glEnable and glDisable with argument GL_LIGHTi.
the ten light parameters are as follows, and bestie, we're going through ALL of them:
๐ 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 โ no clamping, she's free ๐. 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, 0). so light zero is the only one born glowing fr fr โจ
๐ 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, 0).
๐ 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 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. she's pointing straight down the z axis and she has been since birth ๐
๐ 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 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 initially โ so out of the box, this one is lowkey doing nothing. the initial direction is (0, 0, -1).
๐ 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 [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. so 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. zero is the "no thoughts, head empty, evenly lit" setting ๐
๐ 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 [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
๐ GL_LINEAR_ATTENUATION
๐ GL_QUADRATIC_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. three names, one shared description, and they're all iconically unbothered at their defaults โจ
๐ NOTES ๐
it is always the case that GL_LIGHTi = GL_LIGHT0 + i. always. math stays mathing ๐งฎ
๐ ERRORS ๐
GL_INVALID_ENUMis generated if either light or pname is not an accepted value. wrong name, wrong vibe, rejected.GL_INVALID_VALUEis 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_OPERATIONis generated ifglLightis executed between the execution ofglBeginand the corresponding execution ofglEnd. so like. don't do that. the begin/end sandwich is sacred, stay out of it ๐
๐ ASSOCIATED GETS ๐
glGetLightglIsEnabledwith argumentGL_LIGHTING
๐ซถ SEE ALSO ๐ซถ
glColorMaterial(3G)glLightModel(3G)glMaterial(3G)
and that's the whole page, bestie! the little footer at the very bottom is just GLLIGHT(3G) echoing the title back at you like a signature โ same name, same section, a cute lil' bow on the whole thing. it's from the 3G OpenGL manual set, and it says goodbye the exact same way it said hello. go light something up ๐โจ๐
๐ฆ where this page comes from
- opensuse-leap 16.0: Mesa-libGL-devel 24.1.7-160000.3.1 ยท MIT
- opensuse-leap 16.0: Mesa-libGL-devel 24.3.3-160000.3.1 ยท MIT
- opensuse-leap 16.0: Mesa-libGL-devel 24.3.3-160000.3.1 ยท MIT
- opensuse-leap 16.0: Mesa-libGL-devel 24.3.3-160000.3.1 ยท MIT
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms