OpenGL Functions 3 — Questions and Answers
Question 1: What is the function signature purpose of glVertexAttribPointer()?
- Allocates GPU memory for a vertex buffer
- Defines the layout of vertex attribute data in a buffer (Correct answer)
- Enables a vertex attribute array
- Uploads vertex data to the GPU
Correct answer: Defines the layout of vertex attribute data in a buffer
glVertexAttribPointer() tells OpenGL how to interpret the bytes in a bound VBO for a specific vertex attribute index.
Question 2: Which function checks whether a specific OpenGL extension is available?
- glIsEnabled()
- glGetString(GL_EXTENSIONS) (Correct answer)
- glewIsSupported()
- glQueryExtension()
Correct answer: glGetString(GL_EXTENSIONS)
glGetString(GL_EXTENSIONS) returns a space-separated string of all supported extension names (in legacy contexts).
Question 3: What does glReadPixels() do?
- Uploads pixel data to a texture
- Reads a rectangle of pixels from the framebuffer into client memory (Correct answer)
- Copies pixels between framebuffers
- Samples a texture at a given coordinate
Correct answer: Reads a rectangle of pixels from the framebuffer into client memory
glReadPixels() reads a rectangular block of pixel data from the current read framebuffer into a client-side array.
Question 4: Which function must be called after glLinkProgram() to actually use a shader program for rendering?
- glAttachShader()
- glUseProgram() (Correct answer)
- glValidateProgram()
- glBindProgram()
Correct answer: glUseProgram()
glUseProgram() installs the specified program object as part of the current rendering state.
Question 5: What is the role of glScissor()?
- Clips geometry at the vertex stage
- Defines a rectangular region outside which fragments are discarded (Correct answer)
- Sets the viewport transformation
- Masks color buffer writes
Correct answer: Defines a rectangular region outside which fragments are discarded
glScissor() defines a scissor rectangle; any fragments outside this rectangle are automatically discarded before reaching the framebuffer.
Question 6: Which OpenGL function allocates storage for a renderbuffer object?
- glBindRenderbuffer()
- glFramebufferRenderbuffer()
- glRenderbufferStorage() (Correct answer)
- glGenRenderbuffers()
Correct answer: glRenderbufferStorage()
glRenderbufferStorage() establishes the data storage, format, and dimensions for the currently bound renderbuffer object.
Question 7: What does glPolygonOffset() help solve?
- Z-fighting between coplanar surfaces (Correct answer)
- Back-face culling artifacts
- Texture seams at polygon edges
- Overdraw in transparent surfaces
Correct answer: Z-fighting between coplanar surfaces
glPolygonOffset() adds a calculated offset to depth values of polygons, preventing z-fighting when two surfaces are coplanar.
What is the function signature purpose of glVertexAttribPointer()?