OpenGL Computer Graphics 2 — Questions and Answers
Question 1: Which OpenGL function is used to specify the color used when the color buffer is cleared?
- glClearColor() (Correct answer)
- glColor4f()
- glColorMask()
- glClearDepth()
Correct answer: glClearColor()
glClearColor() sets the RGBA values used when glClear(GL_COLOR_BUFFER_BIT) is called.
Question 2: In OpenGL's clip coordinate system, what is the valid range for the w-component after perspective division?
- It must be positive (Correct answer)
- It must equal 1.0
- It can be any non-zero value
- It must be in [-1, 1]
Correct answer: It must be positive
After perspective division, the w component must be positive for a vertex to be on the visible side of the projection plane.
Question 3: What does the OpenGL function glScissor() do?
- Defines a rectangular region outside which all rendering is discarded (Correct answer)
- Clips geometry along arbitrary planes
- Enables stencil testing
- Sets the viewport dimensions
Correct answer: Defines a rectangular region outside which all rendering is discarded
glScissor() defines a rectangular scissor box; fragments outside this box are discarded before the color buffer is updated.
Question 4: Which blending equation makes a fragment fully transparent when its alpha value is 0?
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) (Correct answer)
- glBlendFunc(GL_ONE, GL_ONE)
- glBlendFunc(GL_DST_ALPHA, GL_SRC_ALPHA)
- glBlendFunc(GL_ONE, GL_ZERO)
Correct answer: glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
GL_SRC_ALPHA / GL_ONE_MINUS_SRC_ALPHA is the standard alpha blending equation that makes alpha=0 fragments fully transparent.
Question 5: In OpenGL, what is a Framebuffer Object (FBO) primarily used for?
- Off-screen rendering to textures or renderbuffers (Correct answer)
- Storing vertex attribute data
- Uploading uniform data to shaders
- Managing GPU memory allocation
Correct answer: Off-screen rendering to textures or renderbuffers
FBOs allow rendering to non-default framebuffers, enabling off-screen rendering, render-to-texture, and post-processing effects.
Question 6: What is the purpose of the depth buffer (z-buffer) in OpenGL?
- Correctly rendering objects by discarding fragments hidden behind closer geometry (Correct answer)
- Storing lighting intensity values per pixel
- Accumulating motion blur samples
- Tracking stencil test results
Correct answer: Correctly rendering objects by discarding fragments hidden behind closer geometry
The depth buffer stores per-fragment depth values so that hidden surface removal is performed automatically during rasterization.
Question 7: Which OpenGL primitive mode draws a connected strip of triangles sharing edges?
- GL_TRIANGLE_STRIP (Correct answer)
- GL_TRIANGLE_FAN
- GL_TRIANGLES
- GL_LINE_STRIP
Correct answer: GL_TRIANGLE_STRIP
GL_TRIANGLE_STRIP reuses two vertices from the previous triangle, efficiently drawing n-2 triangles with n vertices.
Which OpenGL function is used to specify the color used when the color buffer is cleared?