GLMATERIAL(3G)
π GLMATERIAL(3G) β bestie, let's talk materials π
okay so this is the GLMATERIAL(3G) page, and it's genuinely one of those pages that sounds scary but is actually just "here's how u tell OpenGL what ur surface is made of". stay with me π«Ά
β¨ NAME β¨
glMaterialf, glMateriali, glMaterialfv, glMaterialiv β specify material parameters for the lighting model
πΈ C SPECIFICATION πΈ
void glMaterialf( GLenum face,
GLenum pname,
GLfloat param )
void glMateriali( GLenum face,
GLenum pname,
GLint param )
π PARAMETERS π
faceβ which face (or faces π) we're updating. Must be one ofGL_FRONT,GL_BACK, orGL_FRONT_AND_BACK.pnameβ the single-valued material parameter of the face/faces being updated. Must beGL_SHININESS.paramβ the value that theGL_SHININESSparameter gets set to.
π C SPECIFICATION (the pointer girlies) π
void glMaterialfv( GLenum face,
GLenum pname,
const GLfloat *params )
void glMaterialiv( GLenum face,
GLenum pname,
const GLint *params )
π¦ PARAMETERS (again, but vector edition) π¦
faceβ which face or faces are being updated. Must be one ofGL_FRONT,GL_BACK, orGL_FRONT_AND_BACK.pnameβ the material parameter of the face or faces being updated. Must be one ofGL_AMBIENT,GL_DIFFUSE,GL_SPECULAR,GL_EMISSION,GL_SHININESS,GL_AMBIENT_AND_DIFFUSE, orGL_COLOR_INDEXES.paramsβ a pointer to the value or values thatpnamewill be set to.
π DESCRIPTION π
glMaterial assigns values to material parameters. there are two matched sets of material parameters, and yes they're a matched set like matching nails π
One set β the front-facing set β is used to shade points, lines, bitmaps, and all polygons (when two-sided lighting is disabled), or just front-facing polygons (when two-sided lighting is enabled). The other set β back-facing β shades back-facing polygons only when two-sided lighting is enabled. For the whole breakdown of one-sided vs two-sided lighting math, go read the glLightModel reference page. it's giving homework but it's important π
glMaterial takes three arguments:
faceβ says whether theGL_FRONTmaterials, theGL_BACKmaterials, or bothGL_FRONT_AND_BACKmaterials get modified.pnameβ says which of several parameters in one or both sets gets modified.paramsβ says what value or values get assigned to that specified parameter.
Material parameters are used in the lighting equation that's optionally applied to each vertex. That equation is discussed over on the glLightModel reference page. The parameters u can set with glMaterial, and how the lighting equation reads them, are:
GL_AMBIENTβparamsholds four integer or floating-point values: the ambient RGBA reflectance of the material. Integer values get mapped linearly so 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. The initial ambient reflectance for both front- and back-facing materials is(0.2, 0.2, 0.2, 1.0).GL_DIFFUSEβparamsholds four integer or floating-point values: the diffuse RGBA reflectance of the material. Integer values get mapped linearly so 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. The initial diffuse reflectance for both front- and back-facing materials is(0.8, 0.8, 0.8, 1.0).GL_SPECULARβparamsholds four integer or floating-point values: the specular RGBA reflectance of the material. Integer values get mapped linearly so 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. The initial specular reflectance for both front- and back-facing materials is(0, 0, 0, 1).GL_EMISSIONβparamsholds four integer or floating-point values: the RGBA emitted light intensity of the material. Integer values get mapped linearly so 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. The initial emission intensity for both front- and back-facing materials is(0, 0, 0, 1).GL_SHININESSβparamsis a single integer or floating-point value: the RGBA specular exponent of the material. Integer and floating-point values are mapped directly. Only values in the range[0,128]are accepted. The initial specular exponent for both front- and back-facing materials is0.GL_AMBIENT_AND_DIFFUSEβ equivalent to callingglMaterialtwice with the same parameter values, once withGL_AMBIENTand once withGL_DIFFUSE. two-for-one deal, we love efficiency β¨GL_COLOR_INDEXESβparamsholds three integer or floating-point values specifying the color indices for ambient, diffuse, and specular lighting. These three values, plusGL_SHININESS, are the only material values used by the color index mode lighting equation. For the full color index lighting discussion, hit up theglLightModelreference page. π
π NOTES π
The material parameters can be updated at any time. In particular, glMaterial can be called between a call to glBegin and the corresponding call to glEnd. iconic, honestly π«Ά
But β if u only need to change a single material parameter per vertex, glColorMaterial is preferred over glMaterial (see glColorMaterial). lowkey a glow-up move, ngl.
While the ambient, diffuse, specular and emission material parameters all have alpha components, only the diffuse alpha component is used in the lighting computation. the other alphas are just there vibing, no cap π
π ERRORS π
GL_INVALID_ENUMis generated if eitherfaceorpnameis not an accepted value.GL_INVALID_VALUEis generated if a specular exponent outside the range[0,128]is specified.
fr fr do NOT pass a shininess outside [0,128] unless u want an error. the range is not a suggestion bestie π
π₯ ASSOCIATED GETS π₯
glGetMaterial
π SEE ALSO π
glColorMaterial(3G)glLight(3G)glLightModel(3G)
and that's the whole page, bestie!! u made it π go forth and shade things beautifully β¨ this was the GLMATERIAL(3G) page β that's the manual name right there in the corner, and this is where the page officially wraps up. mwah π
π¦ 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