Skip to content

MGTheTrain/cpp-opengl-renderer

Repository files navigation

cpp-opengl-renderer

Table of Contents

Summary

A cross-platform C++ OpenGL renderer

Features

  • Compilation on MacOS, Linux Ubuntu 20.04/22.04, Linux debian 11 and Windows 10/11 OS
  • Support for glTF scene loading
  • PBR shader pipeline considering primarily the metal roughness workflow
  • High code coverage with GoogleTest for methods in module structs and classes
  • Create CMakeLists.txt files for cross-platform build environment generation
  • CI workflows ensuring cross-platform compilation primarily for Desktop operating systems
  • CI workflows ensuring continuous testing of the modules
  • Cross-platform CPack packaging for Linux, MacOS and Windows OSes
  • Integrated simple menu (e.g. with sliders and other widgets)
  • Native file dialog support for loading new glTF scenes
  • PBR fragment shader with switchable fragmentColor for inspecting intermediate outcomes (OPTIONAL)
  • Support for USD scene loading (OPTIONAL)
  • Skeletal animation support (OPTIONAL)
  • Port Desktop application to the web trough emscripten SDK (OPTIONAL)
  • Consider compiled library for mobile support trough Java native interface (JNI) with kotlin and Swift native interface (SNI) with Swift (OPTIONAL)

Getting started

Preconditions

Mac OS

Ensure on MacOS you have installed brew with /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Add brew to the PATH variable and substitute <your user> for:

`(echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> /Users/<your user>/.zprofile
    eval "$(/opt/homebrew/bin/brew shellenv)"

Thereafter install the required brew packages/formulas with brew install pkg-config cmake

Debugging

Open the cpp-opengl-renderer.sln. Modify include pathes, library pathes and library names in the cpp-opengl-renderer.vcxproj. Confirm the presence of only one entry point int main(). Set breakpoints as needed. Initiate the debugging process. If you encounter DLL-related errors, make sure to copy the necessary dynamic libraries to the directory where the built executable is located and then rebuild.

Google Test build configurations

Make sure to configure the project settings appropriately for the Debug|x64 build configuration by setting the correct static library path and copying the required shared libraries:

  • Library path: <vcpkg installation path>/vcpkg/packages/gtest_x64-windows/debug/lib
  • Binary path: <vcpkg installation path>/vcpkg/packages/gtest_x64-windows/debug/bin

Similair for Release|x64 build configurations:

  • Library path: <vcpkg installation path>/vcpkg/packages/gtest_x64-windows/lib
  • Binary path: <vcpkg installation path>/vcpkg/packages/gtest_x64-windows/bin

CMake

Unix

In order to compile the source code and link the binaries run in a Unix terminal:

cd devops/scripts/bash/
./compile_source_code.sh -CMakeToolchainFile third-party/vcpkg/scripts/buildsystems/vcpkg.cmake

For web builds ensure the emscripten SDK is installed and then run:

cd devops/scripts/bash/
source <Path to emsdk folder>/emsdk_env.sh
./compile_source_code.sh -WebBuild 
# Copy build artifacts (.js, .wasm, .data) over to assets\web\html-js-wasm
# Start the dev container within the `.devcontainer/nginx` directory. Once inside the container, copy the contents of the assets/web/html-js-wasm directory to /usr/share/nginx/html
# Visit in a browser of choice `localhost:8090/rotating_texture_cube.html` or `localhost:8090/opengl_viewer.html`

In order to additionaly start the test executables in a Unix terminal:

cd devops/scripts/bash/
./compile_source_code.sh -CMakeToolchainFile third-party/vcpkg/scripts/buildsystems/vcpkg.cmake -RunTests

In order to create compressed files or packages:

cd build/
cpack -G <DEB, ZIP, TGZ, TXZ> # DEB only for Linux systems. Check further generators for the specific Unix OS and CPU arch via `cpack -G --help` 
cd ../packages
# install package or unzip compressed file

Windows

In order to compile the source code and link the binaries run in a PowerShell terminal:

cd devops\scripts\ps1
.\compile_source_code.ps1 -CMakeToolchainFile third-party/vcpkg/scripts/buildsystems/vcpkg.cmake

For web builds ensure the emscripten SDK is installed, ninja or mingw32-make are available and then run:

cd devops\scripts\ps1
source <Path to emsdk folder>\emsdk_env.bat
.\compile_source_code.ps1 -WebBuild
# Copy build artifacts (.js, .wasm, .data) over to assets/web/html-js-wasm
# Start the dev container within the `.devcontainer/nginx` directory. Once inside the container, copy the contents of the assets/web/html-js-wasm directory to /usr/share/nginx/html
# Visit in a browser of choice `localhost:8090/rotating_texture_cube.html` or `localhost:8090/opengl_viewer.html`

In order to additionaly start the test executables in a PowerShell terminal:

cd devops\scripts\ps1
.\compile_source_code.ps1 -CMakeToolchainFile third-party/vcpkg/scripts/buildsystems/vcpkg.cmake -RunTests

In order to create compressed files or installers:

cd build/
cpack -G <ZIP, NSIS, NSIS64> # Check further generators for later Windows OSes and CPU arch via `cpack -G --help` 
cd ../packages
# run installer or unzip compressed file

Apps

Images of the rendered scenes can be viewed here: