OpenGL OpenGL Lighting and Materials 2 — Questions and Answers
Question 1: Which OpenGL fixed-function call is used to set material properties used in lighting calculations?
- glMaterialfv() (Correct answer)
- glColorMaterial()
- glSetMaterial()
- glMaterial4f()
Correct answer: glMaterialfv()
glMaterialfv() sets a float vector material parameter such as GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR, or GL_EMISSION for a specified face.
Question 2: Which GL_MATERIAL parameter controls the color of light a surface appears to emit on its own?
- GL_AMBIENT
- GL_DIFFUSE
- GL_EMISSION (Correct answer)
- GL_SPECULAR
Correct answer: GL_EMISSION
GL_EMISSION adds a constant color to the fragment independently of any light source, simulating self-illumination or glowing surfaces.
Question 3: What does enabling GL_COLOR_MATERIAL allow in OpenGL?
- Using textures as material color inputs
- Tracking the current glColor value to automatically set material properties (Correct answer)
- Setting multiple material colors simultaneously
- Applying vertex colors to light source definitions
Correct answer: Tracking the current glColor value to automatically set material properties
GL_COLOR_MATERIAL enables color tracking, where calls to glColor() automatically update the specified material parameter (e.g., GL_DIFFUSE) to match.
Question 4: Phong shading interpolates normals per-fragment and produces smoother highlights than which shading alternative?
- Flat shading
- Gouraud shading (Correct answer)
- Toon shading
- Wireframe shading
Correct answer: Gouraud shading
Gouraud shading computes lighting at vertices and interpolates colors, while Phong shading interpolates normals and evaluates the lighting equation per fragment for smoother specular highlights.
Question 5: What is the primary purpose of surface normal vectors in OpenGL lighting calculations?
- They define texture coordinates for the surface
- They determine how light reflects off the surface (Correct answer)
- They specify the material color
- They control surface transparency
Correct answer: They determine how light reflects off the surface
Normal vectors describe the orientation of a surface at each point, which is used to compute the angle of incidence for diffuse lighting and the reflection direction for specular lighting.
Question 6: In GLSL, which built-in function is most commonly used to ensure a vector has unit length before lighting calculations?
- normalize() (Correct answer)
- length()
- dot()
- cross()
Correct answer: normalize()
normalize() returns a vector with the same direction but magnitude of 1.0, which is required for correct dot-product-based lighting calculations.
Question 7: A GL_SHININESS (specular exponent) value of 128 compared to a value of 1 produces which result?
- A larger, softer specular highlight
- A smaller, sharper specular highlight (Correct answer)
- No visible specular highlight
- A wider colored highlight
Correct answer: A smaller, sharper specular highlight
Higher shininess exponents raise the cosine of the reflection angle to a larger power, causing the specular term to drop off rapidly and produce a tight, sharp highlight.
Which OpenGL fixed-function call is used to set material properties used in lighting calculations?