GLLIGHTMODEL(3G)
β¨ GLLIGHTMODEL π‘ β the 3G manual page, but make it make sense
okay bestie, sit DOWN, because today we're setting the lighting model parameters and it's giving main character energy for your entire scene. π
πΈ NAME πΈ
glLightModelf, glLightModeli, glLightModelfv... no wait, it's glLightModelfv, glLightModeliv β set the lighting model parameters. literally the four functions that decide how your whole vibe gets lit. π
π«Ά C SPECIFICATION π«Ά
void glLightModelf( GLenum pname,
GLfloat param )
void glLightModeli( GLenum pname,
GLint param )
π§ PARAMETERS π§
pnameβ specifies a single-valued lighting model parameter, bestie. The accepted ones areGL_LIGHT_MODEL_LOCAL_VIEWER,GL_LIGHT_MODEL_COLOR_CONTROL, andGL_LIGHT_MODEL_TWO_SIDE. that's the list, no extras. β¨paramβ specifies the value thatparamwill be set to. (yes it says it like that. iconic self-reference tbh.) π
π¦ C SPECIFICATION π¦
round two, and this time there's a pointer involved π«Ά
void glLightModelfv( GLenum pname,
const GLfloat *params )
void glLightModeliv( GLenum pname,
const GLint *params )
π PARAMETERS π
pnameβ specifies a lighting model parameter (plural energy now, not just single-valued). Accepted here:GL_LIGHT_MODEL_AMBIENT,GL_LIGHT_MODEL_COLOR_CONTROL,GL_LIGHT_MODEL_LOCAL_VIEWER, andGL_LIGHT_MODEL_TWO_SIDE. πparamsβ specifies a pointer to the value or values thatparamswill be set to. pointer bestie, we love her. π
π DESCRIPTION π
glLightModel sets the lighting model parameter. pname names a parameter and params gives the new value. There are three lighting model parameters β well, four if you count color control, but the original says three and then lists four, and honestly? slay, we don't gatekeep. π
GL_LIGHT_MODEL_AMBIENTβparamscontains four integer or floating-point values that specify the ambient RGBA intensity of the entire scene. Integer values are mapped linearly such that the most positive representable value maps to1.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 vibe check, no correction, she takes what you give her. The initial ambient scene intensity is(0.2, 0.2, 0.2, 1.0). πΈGL_LIGHT_MODEL_COLOR_CONTROLβparamsmust be eitherGL_SEPARATE_SPECULAR_COLORorGL_SINGLE_COLOR.GL_SINGLE_COLORspecifies that a single color is generated from the lighting computation for a vertex.GL_SEPARATE_SPECULAR_COLORspecifies that the specular color computation of lighting be stored separately from the remainder of the lighting computation β and then the specular color is summed into the generated fragment's color after the application of texture mapping (if enabled). The initial value isGL_SINGLE_COLOR. β¨GL_LIGHT_MODEL_LOCAL_VIEWERβparamsis a single integer or floating-point value that specifies how specular reflection angles are computed. Ifparamsis0(or0.0), specular reflection angles take the view direction to be parallel to and in the direction of the-zaxis, regardless of the location of the vertex in eye coordinates. Otherwise, specular reflections are computed from the origin of the eye coordinate system. The initial value is0. πGL_LIGHT_MODEL_TWO_SIDEβparamsis a single integer or floating-point value that specifies whether one- or two-sided lighting calculations are done for polygons. It has no effect on the lighting calculations for points, lines, or bitmaps. Ifparamsis0(or0.0), one-sided lighting is specified, and only the front material parameters are used in the lighting equation. Otherwise, two-sided lighting is specified. In this case, vertices of back-facing polygons are lighted using the back material parameters, and have their normals reversed before the lighting equation is evaluated. Vertices of front-facing polygons are always lighted using the front material parameters, with no change to their normals. The initial value is0. π«Ά
okay now the β¨mathβ¨ section, and yes bestie it's a lot, but it's literally the lore of how your scene gets its color, so we're reading it together. ππ
In RGBA mode, the lighted color of a vertex is the sum of:
- the material emission intensity,
- the product of the material ambient reflectance and the lighting model full-scene ambient intensity,
- and the contribution of each enabled light source.
Each light source contributes the sum of three terms: ambient, diffuse, and specular.
- The ambient light source contribution is the product of the material ambient reflectance and the light's ambient intensity.
- The diffuse light source contribution is the product of the material diffuse reflectance, the light's diffuse intensity, and the dot product of the vertex's normal with the normalized vector from the vertex to the light source.
- The specular light source contribution is the product of the material specular reflectance, the light's specular intensity, and the dot product of the normalized vertex-to-eye and vertex-to-light vectors, raised to the power of the shininess of the material.
All three light source contributions are attenuated equally based on the distance from the vertex to the light source and on light source direction, spread exponent, and spread cutoff angle. All dot products are replaced with 0 if they evaluate to a negative value. no negative dot products allowed in this house. π
The alpha component of the resulting lighted color is set to the alpha value of the material diffuse reflectance. periodt. π
In color index mode, the value of the lighted index of a vertex ranges from the ambient to the specular values passed to glMaterial using GL_COLOR_INDEXES. Diffuse and specular coefficients, computed with a (.30, .59, .11) weighting of the lights' colors, the shininess of the material, and the same reflection and attenuation equations as in the RGBA case, determine how much above ambient the resulting index is. π
π NOTES π
GL_LIGHT_MODEL_COLOR_CONTROLis available only if the GL version is1.2or greater. bestie if you're on an older GL, that one's just not invited to the party. π
π ERRORS π
GL_INVALID_ENUMis generated ifpnameis not an accepted value. πGL_INVALID_ENUMis generated ifpnameisGL_LIGHT_MODEL_COLOR_CONTROLandparamsis not one ofGL_SINGLE_COLORorGL_SEPARATE_SPECULAR_COLOR.GL_INVALID_OPERATIONis generated ifglLightModelis executed between the execution ofglBeginand the corresponding execution ofglEnd. do NOT do this, the state machine will catch you. π₯
π ASSOCIATED GETS π
glGetwith argumentGL_LIGHT_MODEL_AMBIENTglGetwith argumentGL_LIGHT_MODEL_COLOR_CONTROLglGetwith argumentGL_LIGHT_MODEL_LOCAL_VIEWERglGetwith argumentGL_LIGHT_MODEL_TWO_SIDEglIsEnabledwith argumentGL_LIGHTING
π¦ SEE ALSO π¦
glLight(3G), glMaterial(3G) β your two besties, go read them next, iykyk. π
and that's the whole page, bestie!! π this was the GLLIGHTMODEL page from the 3G manual, dated like every good 3G page is, and the footer literally just says GLLIGHTMODEL(3G) again because the man page format loves a lil bookend. slay, go light something up. π
β¨π
π¦ where this page comes from
- centos-stream 9: gl-manpages 1.1-24.20190306.el9 Β· MIT and Open Publication
- fedora 43: gl-manpages 1.1-34.20190306.fc43 Β· Apache-2.0 AND HPND AND HPND-sell-variant AND MIT AND OpenPBS-2.3 AND SGI-B-2.0 AND W3C-19980720 AND X11
- fedora 44: gl-manpages 1.1-35.20190306.fc44 Β· Apache-2.0 AND HPND AND HPND-sell-variant AND MIT AND OpenPBS-2.3 AND SGI-B-2.0 AND W3C-19980720 AND X11
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms