OpenGL Computer Graphics 4 — Questions and Answers
Question 1: What is a Vertex Array Object (VAO) in modern OpenGL?
- An object that stores the state of vertex attribute bindings and buffer associations (Correct answer)
- A buffer object that stores vertex data
- A shader program that processes vertices
- An OpenGL extension for geometry instancing
Correct answer: An object that stores the state of vertex attribute bindings and buffer associations
A VAO records which VBOs are bound and how vertex attributes are laid out, so the entire state can be restored with a single glBindVertexArray() call.
Question 2: Which OpenGL draw call is most efficient when rendering many identical objects with different transforms?
- glDrawArraysInstanced() (Correct answer)
- glDrawArrays()
- glDrawElements()
- glMultiDrawArrays()
Correct answer: glDrawArraysInstanced()
glDrawArraysInstanced() renders multiple instances in a single draw call, using gl_InstanceID in the shader to differentiate per-instance data.
Question 3: In Phong lighting, which component is independent of the viewer's position?
- Ambient and diffuse (Correct answer)
- Specular only
- Ambient only
- Diffuse and specular
Correct answer: Ambient and diffuse
Ambient is a constant term and diffuse depends only on the light direction and surface normal, not the viewer position; specular does depend on the view vector.
Question 4: What does 'gl_FragCoord' represent in a GLSL fragment shader?
- The window-space position (x, y, z, 1/w) of the fragment (Correct answer)
- The object-space position of the surface point
- The interpolated texture coordinate
- The eye-space surface normal
Correct answer: The window-space position (x, y, z, 1/w) of the fragment
gl_FragCoord holds the fragment's position in window space, where x and y are pixel coordinates and z is the depth value written to the depth buffer.
Question 5: What is the effect of setting the texture wrap mode to GL_CLAMP_TO_EDGE?
- Texture coordinates outside [0,1] are clamped to the nearest edge texel (Correct answer)
- The texture tiles infinitely in both directions
- The texture coordinate wraps around using modulo
- Coordinates outside [0,1] sample a user-defined border color
Correct answer: Texture coordinates outside [0,1] are clamped to the nearest edge texel
GL_CLAMP_TO_EDGE prevents texture bleeding by clamping coordinates to [0.5/N, 1-0.5/N], sampling only edge texels for out-of-range coordinates.
Question 6: Which OpenGL feature allows the geometry shader to generate additional primitives?
- Geometry shaders can emit vertices and use EmitVertex()/EndPrimitive() (Correct answer)
- Tessellation control shaders
- Transform feedback
- Compute shaders with image store
Correct answer: Geometry shaders can emit vertices and use EmitVertex()/EndPrimitive()
Geometry shaders are optional pipeline stages that receive complete primitives and can emit zero or more new primitives using EmitVertex() and EndPrimitive().
Question 7: In a perspective projection, what happens to objects as their distance from the camera increases?
- They appear smaller due to the perspective divide (Correct answer)
- They appear larger because depth values scale up
- Their size remains constant — only depth changes
- They are clipped by the near plane
Correct answer: They appear smaller due to the perspective divide
In perspective projection, dividing by the eye-space z value makes objects farther from the camera project to smaller screen-space sizes.
What is a Vertex Array Object (VAO) in modern OpenGL?