Skip to content

Latest commit

 

History

History
213 lines (149 loc) · 6.41 KB

README.md

File metadata and controls

213 lines (149 loc) · 6.41 KB

Real-time C++ 3D renderer with OpenGL/WebGL

Build

A hardware-accelerated 3D renderer written in C++. Runs using OpenGL 4.6 or 3.3 as graphics API on desktop and WebGL2 in web browsers.

Click here for Rust version of this project

Demo

demo.mp4

Table of Contents

Try it out!

Motivation

This project is a demonstration of my expertise to write cross-platform 3D graphical applications in C++ that run on both desktop (Windows, Linux) and on the web with WebAssembly. I use this project as a sandbox to prototype graphics programming techniques and plan to use it as reference when doing native game engine development at home.

The project showcases confident usage of the following technologies:

  • C++20
  • 3D graphics programming with OpenGL 4.6, OpenGL 3.3, WebGL2 (based on OpenGL ES 3.0)
  • Advanced CMake practices (modern CMake targets, FetchContent, CPack)
  • Immediate mode overlay GUI using Dear ImGui (as opposed to retained mode GUI frameworks like Qt)
  • Building for WebAssembly using Emscripten
  • Clang Tooling (clang-format, clang-tidy)

Future additions will include Direct3D, Vulkan rendering backends and additional post-processing effects.

Features

  • 3D model display from OBJ file format
  • Fly-by FPS camera movement
  • Skybox display using cube-map
  • Add multiple objects dynamically into the scene and manipulate their positions, rotations, colors, and selected meshes separately.

Scene outline

  • Runtime selectable rendering backends from a drop-down list

Drop-down list

  • Directional light with ADS (Ambient, Diffuse, Specular) lighting (Phong shading)
  • Live browser demo

Requirements

Desktop executable requires at least an OpenGL 3.3 compatible graphics adapter to run. The application attempts to target the highest OpenGL 4.6 version and chooses OpenGL 3.3 as fallback. Check if your hardware supports OpenGL and make sure to have the latest graphics driver installed to avoid any errors.

Web browser live demo requires support for WebGL2.

Required build tools:

  • C++20 compiler
  • CMake 3.16 or newer

Required dependencies on Debian, Ubuntu, Linux Mint:

sudo apt install libwayland-dev libxkbcommon-dev xorg-dev

Required dependencies on Fedora, Red Hat:

sudo dnf install wayland-devel libxkbcommon-devel libXcursor-devel libXi-devel libXinerama-devel libXrandr-devel

All other dependencies are either included in thirdparty folder or automatically downloaded and built by FetchContent feature of CMake.

Build instructions

  1. Clone the repository
git clone https://github.com/balintkissdev/3d-renderer-cpp.git
cd 3d-renderer-cpp
  1. Configure the project with CMake. -B build also creates a new folder called build where the files during build will be generated, avoiding polluting the project root folder.
cmake -B ./build

Treating compiler warnings as errors is turned off by default but can be enabled with -DBUILD_WERROR=ON during the CMake configuration. This is because the common practice in open-source projects is to not enable build warnigns as errors by default, avoiding situations where people with different build environments encounter warnings that prevent them from building without modifying the CMakeLists.txt file. Warnings as errors are enabled for automated CI builds.

  1. Build the project
cmake --build ./build --config Release

Generate Windows release

This will be a ZIP file on Windows.

cpack -B ./build -C "Release"

Generate Linux release

This will be an AppImage file on Linux. Generation requires FUSE version 2 to be installed (see https://github.com/AppImage/AppImageKit/wiki/FUSE).

cd build
make install DESTDIR=.

WebAssembly build

Install Emscripten on your system then issue the commands for configure and build similar as before, but in the Emscripten build environment.

source <emsdk install location>/emsdk_env.sh

emcmake cmake -B ./build
emcmake cmake --build ./build --config Release

Opening the resulting 3Drenderer.html file with the browser will not work because of default browser CORS rules. You can either use a live server locally to access at http://localhost:8000

cd build
python -m http.server

or alternatively use emrun 3DRenderer.html --port 8000.

Usage

After building, run the executable in the build directory. On Windows:

cd build
3DRenderer.exe

On Linux:

cd build
./3DRenderer

Use keyboard and mouse to navigate the 3D environment.

  • Movement: W, A, S, D
  • Mouse look: Right-click and drag
  • Ascend: Spacebar
  • Descend: C

Modify UI controls to change properties of the 3D scene display.

Acknowledgements