GLMATERIAL(3G)

πŸ“¦ version 1.1, in centos-stream 9, fedora 43, fedora 44

πŸ’… 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 of GL_FRONT, GL_BACK, or GL_FRONT_AND_BACK.
  • pname β€” the single-valued material parameter of the face/faces being updated. Must be GL_SHININESS.
  • param β€” the value that the GL_SHININESS parameter 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 of GL_FRONT, GL_BACK, or GL_FRONT_AND_BACK.
  • pname β€” the material parameter of the face or faces being updated. Must be one of GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR, GL_EMISSION, GL_SHININESS, GL_AMBIENT_AND_DIFFUSE, or GL_COLOR_INDEXES.
  • params β€” a pointer to the value or values that pname will 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:

  1. face β€” says whether the GL_FRONT materials, the GL_BACK materials, or both GL_FRONT_AND_BACK materials get modified.
  2. pname β€” says which of several parameters in one or both sets gets modified.
  3. 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 β€” params holds 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 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 reflectance for both front- and back-facing materials is (0.2, 0.2, 0.2, 1.0).
  • GL_DIFFUSE β€” params holds 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 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 diffuse reflectance for both front- and back-facing materials is (0.8, 0.8, 0.8, 1.0).
  • GL_SPECULAR β€” params holds 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 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 specular reflectance for both front- and back-facing materials is (0, 0, 0, 1).
  • GL_EMISSION β€” params holds 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 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 emission intensity for both front- and back-facing materials is (0, 0, 0, 1).
  • GL_SHININESS β€” params is 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 is 0.
  • GL_AMBIENT_AND_DIFFUSE β€” equivalent to calling glMaterial twice with the same parameter values, once with GL_AMBIENT and once with GL_DIFFUSE. two-for-one deal, we love efficiency ✨
  • GL_COLOR_INDEXES β€” params holds three integer or floating-point values specifying the color indices for ambient, diffuse, and specular lighting. These three values, plus GL_SHININESS, are the only material values used by the color index mode lighting equation. For the full color index lighting discussion, hit up the glLightModel reference 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_ENUM is generated if either face or pname is not an accepted value.
  • GL_INVALID_VALUE is 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