OpenGL Functions 5 — Questions and Answers
Question 1: Which function sets the clear color used by glClear(GL_COLOR_BUFFER_BIT)?
- glColor4f()
- glClearColor() (Correct answer)
- glColorMask()
- glBlendColor()
Correct answer: glClearColor()
glClearColor() specifies the RGBA values that the color buffer is filled with when glClear(GL_COLOR_BUFFER_BIT) is called.
Question 2: What does glVertexAttribDivisor(index, 1) do?
- Steps the attribute once per vertex
- Steps the attribute once per instance during instanced rendering (Correct answer)
- Disables the attribute for all instances
- Divides vertex positions by the instance count
Correct answer: Steps the attribute once per instance during instanced rendering
Setting the divisor to 1 causes the attribute to advance once per instance rather than once per vertex, enabling per-instance data in instanced rendering.
Question 3: Which function is used to bind a named texture object to a texturing target?
- glGenTextures()
- glActiveTexture()
- glBindTexture() (Correct answer)
- glTexImage2D()
Correct answer: glBindTexture()
glBindTexture() makes a texture object current for subsequent texture operations on the specified target such as GL_TEXTURE_2D.
Question 4: What is the effect of calling glEnable(GL_CULL_FACE) with the default cull face setting?
- Front-facing triangles are discarded
- Back-facing triangles are discarded (Correct answer)
- Both front and back faces are discarded
- No faces are discarded until glCullFace() is called
Correct answer: Back-facing triangles are discarded
By default, glEnable(GL_CULL_FACE) discards back-facing triangles because the default cull face is GL_BACK.
Question 5: Which function queries a program object for information such as link status?
- glGetShaderiv()
- glGetProgramiv() (Correct answer)
- glValidateProgram()
- glProgramInfo()
Correct answer: glGetProgramiv()
glGetProgramiv() retrieves integer properties of a program object, including GL_LINK_STATUS and GL_ACTIVE_UNIFORMS.
Question 6: What does glBindVertexArray(0) accomplish?
- Deletes the currently bound VAO
- Unbinds the current VAO, restoring the default state (Correct answer)
- Binds the default vertex array provided by OpenGL
- Resets all vertex attribute pointers to null
Correct answer: Unbinds the current VAO, restoring the default state
Passing 0 to glBindVertexArray() unbinds any currently bound VAO, preventing accidental modification of its state.
Question 7: Which function is used to specify data for a uniform matrix variable in a shader?
- glUniform4fv()
- glUniformMatrix4fv() (Correct answer)
- glVertexAttrib4fv()
- glProgramUniform4f()
Correct answer: glUniformMatrix4fv()
glUniformMatrix4fv() uploads one or more 4x4 float matrices to a uniform location in the currently active program.
Which function sets the clear color used by glClear(GL_COLOR_BUFFER_BIT)?