OpenGL OpenGL Rendering Pipeline 2 — Questions and Answers
Question 1: What is the purpose of the depth test in OpenGL?
- Ensures fragments closer to the camera overwrite farther ones (Correct answer)
- Blends transparent fragments together
- Removes duplicate texture samples
- Converts normals to depth values
Correct answer: Ensures fragments closer to the camera overwrite farther ones
The depth test compares each fragment's z value against the depth buffer, keeping only the closest fragment per pixel.
Question 2: What does glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) do?
- Deletes all textures and buffers
- Resets the color and depth buffers to their clear values before rendering a new frame (Correct answer)
- Swaps the front and back buffers
- Unbinds all currently bound buffers
Correct answer: Resets the color and depth buffers to their clear values before rendering a new frame
glClear with those flags fills the color buffer with the clear color and the depth buffer with 1.0 (far), preparing for the next frame.
Question 3: What OpenGL blending equation produces standard over-compositing for transparent objects?
- GL_ONE, GL_ZERO
- GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA (Correct answer)
- GL_DST_COLOR, GL_SRC_COLOR
- GL_ONE, GL_ONE
Correct answer: GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) blends source and destination by the fragment's alpha, the standard transparency blend.
Question 4: Which OpenGL feature limits rendering to a rectangular sub-region of the framebuffer?
- glViewport
- glScissor (Correct answer)
- glDepthRange
- glColorMask
Correct answer: glScissor
glScissor(x, y, width, height) with GL_SCISSOR_TEST enabled discards all fragments outside the defined rectangle.
Question 5: What OpenGL function swaps the front and back buffers to display the completed frame?
- glFlush
- glFinish
- SwapBuffers (platform API) (Correct answer)
- glPresent
Correct answer: SwapBuffers (platform API)
Buffer swapping is a platform-level operation (e.g., SDL_GL_SwapWindow or SwapBuffers on Windows) not an OpenGL core function.
Question 6: Which OpenGL face culling mode keeps only front-facing triangles?
- glCullFace(GL_FRONT)
- glCullFace(GL_BACK) (Correct answer)
- glCullFace(GL_FRONT_AND_BACK)
- glFrontFace(GL_CW)
Correct answer: glCullFace(GL_BACK)
glCullFace(GL_BACK) combined with glEnable(GL_CULL_FACE) discards back-facing triangles, the most common culling setup.
What is the purpose of the depth test in OpenGL?