Skip to content

Latest commit

 

History

History
49 lines (33 loc) · 1.94 KB

File metadata and controls

49 lines (33 loc) · 1.94 KB

Lesson 04 : Models

Learning goals

  • Load models from Wavefront files into OpenGL
  • Understand vertex normals

Compilation instructions

Build from the repository root in a MinGW-w64 shell.

mkdir build
cmake -S lesson04 -B build/lesson04 -G "MinGW Makefiles"
cmake --build build/lesson04

Explanation

In the previous lesson, we created a separate class to handle the Shader. To continue on this path, in this lesson we use a separate class to handle objects. The objects are loaded from wavefront .obj files. Such files can be exported using a program such as Blender.

Loading the model has basically become a one-liner

Model monkey("../" + lesson_id + "/assets/models/monkey.obj");

What the class does is open the file monkey.obj, read the contents, construct a vao and several vbo and place the contents of the object in the corresponding buffers. In detail, this means that vertex and normal data is copied to the buffers and the indices are created that form the triangles.

To draw the object, simply call the draw function within the loop as follows

monkey.draw();

Running the program

occ-lesson-04

Normal projection

Loading models

Coordinate system

Exercises

Exercise 01: Drawing multiple monkeys

Alter the program in such a way that not one, but four monkeys are being drawn. Note that you do not have to create a separate object for each monkey, you can simply call the draw command again. Try to explain why simply calling the draw command is sufficient.

To further practice with the learning goals of this lesson. A series of exercises are introduced as can be found below. Solution to these exercises are given here.