Loading a 3D model from an OBJ file
Rendering 3D scenes requires us to draw objects, which are also called models or meshes. A mesh is a collection of vertices (points) with information about how these vertices form surfaces or faces (usually triangles).
Objects are prepared in modeling software or CAD programs. They can be stored in many various formats, which are later loaded in 3D applications, provided to graphics hardware, and then rendered. One of the simpler file types, which holds mesh data, is a Wavefront OBJ. We will learn how to load models stored in this format.
Getting ready
There are multiple libraries that allow us to load OBJ files (or other file types). One of the simpler, yet very fast and still being improved, libraries is a tinyobjloader developed by Syoyo Fujita. It is a single header library, so we don't need to include any other files or reference any other libraries.
Note
The tinyobjloader library can be downloaded from https://github.com/syoyo/tinyobjloader.
To use the...