OpenGL Computer Graphics 3 — Questions and Answers
Question 1: In GLSL, which built-in variable contains the interpolated texture coordinate passed from the vertex shader to the fragment shader?
- A user-defined 'varying' or 'in' variable (Correct answer)
- gl_FragCoord
- gl_TexCoord
- gl_Position
Correct answer: A user-defined 'varying' or 'in' variable
Texture coordinates are user-defined 'out' variables in the vertex shader and matching 'in' variables in the fragment shader, interpolated by the rasterizer.
Question 2: What OpenGL call uploads a 2D texture image to the GPU?
- glTexImage2D() (Correct answer)
- glBindTexture()
- glGenTextures()
- glActiveTexture()
Correct answer: glTexImage2D()
glTexImage2D() specifies the mipmap level, internal format, dimensions, and pixel data for a 2D texture.
Question 3: What is mipmapping in OpenGL texturing?
- A series of pre-computed, progressively smaller texture images for minification (Correct answer)
- A technique to increase texture resolution dynamically
- Layered textures for cube mapping
- A method of compressing texture data on the GPU
Correct answer: A series of pre-computed, progressively smaller texture images for minification
Mipmaps are pre-filtered downsampled versions of a texture used when the textured surface is far from the camera to avoid aliasing.
Question 4: Which matrix transforms 3D eye-space coordinates into clip coordinates in a classic OpenGL pipeline?
- Projection matrix (Correct answer)
- Model matrix
- View matrix
- Normal matrix
Correct answer: Projection matrix
The projection matrix (perspective or orthographic) maps eye-space coordinates to the clip volume, defining the viewing frustum.
Question 5: What does the GLSL function 'normalize()' return?
- A vector with the same direction but a magnitude of 1.0 (Correct answer)
- The component-wise absolute value of the input
- The dot product of a vector with itself
- A vector clamped between 0.0 and 1.0
Correct answer: A vector with the same direction but a magnitude of 1.0
normalize(v) divides the vector by its length, returning a unit vector used frequently in lighting calculations.
Question 6: In OpenGL's stencil test, what does 'GL_KEEP' do when specified as the stencil operation?
- Leaves the stencil buffer value unchanged (Correct answer)
- Sets the stencil buffer value to zero
- Inverts all bits of the stencil value
- Replaces the stencil value with the reference value
Correct answer: Leaves the stencil buffer value unchanged
GL_KEEP is the no-op stencil operation that preserves the existing stencil value when the corresponding test result occurs.
Question 7: What is the purpose of calling glGenerateMipmap() after uploading a texture?
- Automatically generates all mipmap levels from the base level image (Correct answer)
- Compresses the texture to save VRAM
- Enables anisotropic filtering for the texture
- Binds the texture to all available texture units
Correct answer: Automatically generates all mipmap levels from the base level image
glGenerateMipmap() instructs the GPU to compute the full mipmap chain from the base texture image already uploaded.
In GLSL, which built-in variable contains the interpolated texture coordinate passed from the vertex shader to the fragment shader?