Rory.games OBJ Loader

Rory.games

OBJ Loader

The OBJ Loader is a program written in C++ to load and view .obj files in 3D space using OpenGL.

It allows for texture loading, diffuse and specular lighting, full rotation and an extensive set of user defined options such as resolution, OpenGL versions and custom shaders.

There is an included GUI and details window that allows for the user to see information such as frame rate, vertices and colour and texture data.

Browse Source Code

View the GitHub page.

The program uses SDL2 for input and window management, GLEW for OpenGL, GLM for object transformations and utilizes GLSL for shaders.

Objects are read from .obj files using string streams, stored in vertex buffer arrays with the positions and normals passed as vector3s and the UV coordinates passed as vector2s.

The MVP matrix is controller in the code and each part is passed separately to the shader, allowing for full model rotation control with lighting being correctly rendered.

There is a full set of vertex and fragment shaders included with the source code that allow for external texture files with diffuse and specular lighting.

Overall colour values for the pixels are calculated by adding the ambient colour of the model with the diffuse colour (which we get from the texture or user definition) times by the colour of the light, it's power and the cosine of the angle between the normal of the pixel and the lights direction which is also based on the distance.

Finally we add the specular colour (in this case a grey of 30%), once again times by the light colour, power and then the cosine of whether the light is directly reflecting towards the camera or elsewhere.

I implemented a configuration/settings window into the application that allows for the user to see statistics and a fully mouse controlled GUI. This is done in a different method to the main window as it simply uses SDL2 for its output and double buffering. Although it may be a separate window it is attached to the main window at all times, each window is part of the program so keyboard input can be used from either.