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.mp4
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.
- 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.
- Runtime selectable rendering backends from a drop-down list
- Directional light with ADS (Ambient, Diffuse, Specular) lighting (Phong shading)
- Live browser demo
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.
- Clone the repository
git clone https://github.com/balintkissdev/3d-renderer-cpp.git
cd 3d-renderer-cpp
- Configure the project with CMake.
-B build
also creates a new folder calledbuild
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.
- Build the project
cmake --build ./build --config Release
This will be a ZIP file on Windows.
cpack -B ./build -C "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=.
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
.
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.
- Utah Teapot and Stanford Bunny model meshes are from Stanford Computer Graphics Laboratory
- High poly Stanford Bunny model mesh is from https://www.prinmath.com/csci5229/OBJ/index.html
- Skybox texture images are from learnopengl.com