/opengl-model-viewer

A real-time renderer for .stl files using OpenGL and C++

Primary LanguageC++MIT LicenseMIT

OpenGL Model Viewer

This project is a real-time renderer for .stl format files, built using the OpenGL graphics API. I primarily used Joey de Vries' tutorials at learnopengl.com to teach myself OpenGL, and they inspired much of this design.

Features

Fully adjustable ambient, diffuse and specular (Phong) lighting

Alien

Mouse, scroll and keyboard controls for oribiting and zooming around the model

Bust

Explode effect on start

Elephant

Ability to load high-detail (> 1 million polygons) models

Head

Adjustable FOV

Rat

Sample models retrieved from turbosquid.com:

Files

File Contents
main.cpp config.ini file parsing, GLFW setup, OpenGL setup, input processing functions and main rendering loop
camera.hpp/cpp Camera class: stores camera position and angle state, handles camera movement and FOV adjustment, calculates view and projection matrices
mesh.hpp/cpp Mesh class: loads and stores mesh vertices and indices, draws meshes
model.hpp/cpp Model class: recursively processes, loads and stores meshes, iteratively draws those meshes
shader.hpp/cpp Shader class: loads, compiles, links and binds shaders, updates shader uniforms
shaders/model/*.glsl GLSL shaders for the model. geometry.glsl only exists for explode effect
config.ini Configuration file for changing any model, material, lighting, graphical or window properties that may need to be customized. I have future plans to move this configuration to a GUI

Dependencies

Library Description Link
OpenGL Open-source graphics API, written by graphics hardware manufacturers. This project uses version 4.1 as it is pre-installed on all modern MacOS devices Website
GLFW Cross-platform library used for window management, OpenGL context management, and user input processing Website
Assimp Library for importing 3D models Website
GLM Math library for OpenGL programming, designed with GLSL in mind. Used for vector and matrix operations Website
inih .ini file parsing library. Used to parse config.ini Original Library
Header-only version used

Build

This project has not been tested on any platforms other than my development machine (2018 MBP). I may look into improving this in the future.

opengl-model-viewer is expected to work on all MacOS machines, but this is unverified. It will not work on Windows or Linux machines without modifcation to the OpenGL importing process (this project uses the preinstalled OpenGL found on MacOS, and therefore does not use a extension loading library such as GLEW). The GLFW installation should also be modified as it is now using a MacOS-only pre-compiled binary. Assimp, GLM, and inih should not need modification for building on other systems.