OpenGL Programming Pt2 Flashcards

(36 cards)

1
Q

Q1: Why do we need to load external models in OpenGL?

A

A1: Because real 3D models have thousands of vertices and can’t be manually hardcoded — they must be loaded from files like .obj.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Q2: What is the purpose of a model file in 3D graphics?

A

A2: It stores the vertex positions, normals, and indices that describe a 3D object’s shape and structure.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Q3: What are common sources of 3D models?

A

A3: Engineering/scientific data or assets created in modeling software like Blender, Maya, or 3ds Max.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Q4: What model format is commonly used in OpenGL teaching examples?

A

A4: .obj (Wavefront Object).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Q5: What are the advantages of the OBJ format?

A

A5: It’s text-based, human-readable, platform-independent, and easy to find or create.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Q6: What is a disadvantage of the OBJ format?

A

A6: It’s slow to load for large models because it’s not binary and may include redundant data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Q7: What library is used to load .obj models?

A

A7: TinyOBJLoader — a lightweight C++ library that parses OBJ files and provides vertices, normals, and indices.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Q8: What kind of data does TinyOBJLoader extract?

A

Vertex positions

Normals

Indices (faces)

Material information

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Q9: Why are arrays like vertices and normals declared as pointers?

A

A9: Because their sizes aren’t known until the model file is read, so memory is allocated dynamically.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Q10: What is a bounding box?

A

A10: The smallest 3D box that completely encloses a model — defined by (xmin, xmax, ymin, ymax, zmin, zmax).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Q11: Why compute a bounding box when loading a model?

A

To know the model’s size and position

To scale or center it in view

To position the camera correctly

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Q12: Why can’t we use sizeof(vertices) when uploading data to the GPU?

A

A12: Because vertices is a pointer, not a fixed array — you must use num_vertices * sizeof(GLfloat) instead.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Q13: What buffers are used to send data to the GPU?

A

VBO (Vertex Buffer Object) for vertices and normals

EBO (Element Buffer Object) for indices

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Q14: Why is glBufferSubData used after glBufferData?

A

A14: To fill different parts of the same buffer (e.g., first the vertices, then the normals).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Q15: Why might your model disappear after “cleaning” your Visual Studio project?

A

A15: The .obj model file has the same extension as compiled .obj files, so Visual Studio deletes it when cleaning. Keep it in a separate folder.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Q16: What happens if vertex order and normal order don’t match?

A

A16: Lighting will be incorrect because normals point in the wrong directions.

17
Q

Q17: How can you fix incorrect normals in a model?

A

A17: Use a tool like MeshLab → Filters → Normals, Curvature, and Orientation → Recompute Vertex Normals.

18
Q

Q18: Why might multiple models have mismatched appearance or size?

A

A18: Different coordinate systems (Y-up vs. Z-up) and inconsistent scales between models.

19
Q

Q19: What structure is used to represent each model in code?

A

struct Mesh {
GLuint vbuffer, ibuffer;
GLuint triangles, vbytes;
GLuint program;
glm::mat4 model;
};

20
Q

Q20: What is stored inside each Mesh?

A

A20: GPU buffer IDs, triangle count, assigned shader program, and its model transformation matrix.

21
Q

Q21: Why do we normalize models after loading?

A

Q21: Why do we normalize models after loading?

22
Q

Q22: How do you normalize a model’s size?

A

Find the bounding box size in x, y, and z.

Compute the maximum dimension.

Divide all vertex coordinates by that value

23
Q

Q23: Why is normalization important in multi-object scenes?

A

A23: It ensures different models (like a monkey and bunny) appear properly scaled and centered in the same scene.

24
Q

Q24: Why shouldn’t you recompile shaders for each model?

A

A24: It’s inefficient — instead, compile them once and reuse the program across models.

25
Q25: How do you reuse the same shader for multiple models?
A25: Store the program ID in each mesh’s struct and call glUseProgram(mesh->program) before drawing.
26
Q26: How can you draw multiple copies of the same object?
A26: Duplicate the mesh structure, reuse the same vertex/index data, and apply different model transformations.
27
Q27: Why is this approach memory efficient?
A27: All copies share the same geometry buffers; only the transformation matrix changes.
28
Q28: How do you render multiple models in the display loop?
for (mesh in Model) { glUseProgram(mesh->program); set attributes; send matrices; draw elements; }
29
Q29: Which matrix combination is used for each object’s final position?
A29: Model-View-Projection (MVP) = projection * view * model.
30
Q30: Why do we use a special matrix to transform normals?
A30: Because scaling or rotation can distort them; we need to preserve perpendicularity for lighting.
31
Q31: What is the correct matrix for transforming normals?
A31: The inverse transpose of the model-view matrix: glm::transpose(glm::inverse(glm::mat3(view * model))).
32
Q32: What does TinyOBJLoader do in the OpenGL pipeline?
A32: It reads model data from a .obj file and provides vertices, normals, and indices for GPU upload.
33
Q33: What’s the purpose of the bounding box?
A33: To determine model size and positioning for scaling, centering, and camera setup.
34
Q34: Why is rescaling models important?
A34: Ensures all models fit within a consistent space for unified viewing.
35
Q35: What’s the role of the Mesh structure?
A35: To store all rendering-related data and transformation info for each object in the scene.
36
Q36: Why use the inverse transpose for normals?
A36: To correct distortions caused by non-uniform scaling and preserve accurate lighting.