Skip to content
This repository was archived by the owner on Mar 22, 2026. It is now read-only.

MGTheTrain/cpp-opengl-renderer

Repository files navigation

cpp-opengl-renderer

Summary

A cross-platform C++ OpenGL renderer supporting glTF scene loading with a PBR metal-roughness shader pipeline.

Features

  • Compilation on macOS, Ubuntu 24.04, Debian 12, Windows 11
  • glTF scene loading via tinygltf
  • PBR shader pipeline (metal-roughness workflow)
  • Image-based lighting (IBL) with equirectangular HDR environment maps
  • ImGui settings panel (sliders, checkboxes, native file dialog for scene selection)
  • GoogleTest coverage for module structs and classes
  • CMake + vcpkg cross-platform build system
  • CI workflows for cross-platform compilation and continuous testing with versioned packages
  • CPack packaging for Linux (DEB, TGZ, ZIP), macOS (TGZ, ZIP), Windows (ZIP) and Web (TGZ)
  • Web port via Emscripten
  • PBR fragment shader with switchable fragmentColor for inspecting intermediate outputs (optional)
  • USD scene loading (optional)
  • Skeletal animation (optional)
  • Mobile support via JNI (Kotlin) and Swift native interface (optional)

Prerequisites

  • CMake ≥ 3.10
  • vcpkg (bootstrapped via third-party/vcpkg submodule)
  • For glTF sample scenes: git submodule update --init assets/scenes/glTF-Sample-Models
  • For web builds: Emscripten SDK

Code Quality

pre-commit (formatting and linting — no build required):

pip install pre-commit
pre-commit run --all-files

clang-tidy (static analysis — requires a compilation database):

cmake -B build \
    -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
    -DCMAKE_BUILD_TYPE=Debug \
    -DBUILD_LIB=ON -DBUILD_APP=ON -DBUILD_TEST=OFF \
    -DCMAKE_TOOLCHAIN_FILE=/tmp/vcpkg/scripts/buildsystems/vcpkg.cmake

# All files
find modules apps -name '*.cpp' | grep -v third-party \
  | xargs -P$(nproc) clang-tidy -p build --config-file=.clang-tidy

# Changed files only (faster during development)
git diff --name-only HEAD | grep '\.cpp$' \
  | xargs clang-tidy -p build --config-file=.clang-tidy

SonarCloud (deep semantic and security analysis — requires a SonarCloud account):

# Prerequisites
brew install sonar-scanner   # macOS
export SONAR_TOKEN=<your-token>

# Run locally
./scripts/sonar-scan.sh

Results are published to sonarcloud.io. All three checks run automatically in CI on every pull request and push to main.

Getting Started

macOS / Linux

Desktop build:

cd scripts/
./build.sh -CMakeToolchainFile ../third-party/vcpkg/scripts/buildsystems/vcpkg.cmake -Release

With tests:

cd scripts/
./build.sh -CMakeToolchainFile ../third-party/vcpkg/scripts/buildsystems/vcpkg.cmake -RunTests

With versioned package suffix:

cd scripts/
./build.sh -CMakeToolchainFile ../third-party/vcpkg/scripts/buildsystems/vcpkg.cmake -Release -RevisionNumber alpha-1

Web build:

cd scripts/
source <path-to-emsdk>/emsdk_env.sh
./build.sh -WebBuild
# Copy build artifacts (.js, .wasm, .data) to assets/web/html-js-wasm
# Start the nginx dev container in .devcontainer/nginx, copy artifacts to /usr/share/nginx/html
# Open http://localhost:8090/rotating_textured_cube.html or http://localhost:8090/opengl_viewer.html

Packaging:

cd build/
cpack --config CPackConfig.cmake -G DEB   # Linux
cpack --config CPackConfig.cmake -G TGZ   # Linux / macOS
cpack --config CPackConfig.cmake -G ZIP   # Linux / macOS

Windows

Desktop build:

cd scripts\
.\build.ps1 -CMakeToolchainFile ..\third-party\vcpkg\scripts\buildsystems\vcpkg.cmake -Release

With tests:

cd scripts\
.\build.ps1 -CMakeToolchainFile ..\third-party\vcpkg\scripts\buildsystems\vcpkg.cmake -RunTests

With versioned package suffix:

cd scripts\
.\build.ps1 -CMakeToolchainFile ..\third-party\vcpkg\scripts\buildsystems\vcpkg.cmake -Release -RevisionNumber alpha-1

Packaging:

cd build\
cpack --config CPackConfig.cmake -G ZIP

Apps

App Description
opengl-viewer Full PBR viewer with IBL and ImGui settings panel
rotating-textured-cube Minimal textured cube demo

About

A cross-platform C++ OpenGL renderer supporting glTF scene loading with a PBR metal-roughness shader pipeline

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors