Skip to content

SDL2-based wireframe demo that rotates and projects simple 3D primitives (cube, pyramid) to 2D.

License

Notifications You must be signed in to change notification settings

PavolUlicny/3DRenderer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

3DRenderer

SDL2-based wireframe demo that rotates and projects simple 3D primitives (cube, pyramid) to 2D. The window is resizable and input is mapped to simple state changes.

Demo

Cube demo
Cube demo

Project structure

Files and responsibilities

  • Build system: Makefile — targets for debug (all), run, release, and AddressSanitizer.
  • Entry point: main.cpp — initializes RenderState, picks a primitive, starts the render loop.
  • SDL render loop API: 2d_renderer.hrenderer_run declaration and frame-callback type.
  • SDL render loop impl: 2d_renderer.cpp — creates the resizable window and VSync renderer, polls events, clears/presents, and invokes the per-frame callback.
  • 3D math + callback API: 3d_renderer.h — rotation/project utilities and the frame_callback signature.
  • 3D math + callback impl: 3d_renderer.cpp — rotation around X/Y/Z, perspective projection, and the per-frame render callback.
  • 3D objects API: objects_3d.h — primitive builders (cube, pyramid).
  • 3D objects impl: objects_3d.cpp — implementations populating RenderState.
  • Shared app state and types: app_state.hPoint3d, Point2d, Edge3d, and RenderState (geometry, projection, rotation, timing, lifecycle).
  • Input mapping API: input.hhandleEvent declaration.
  • Input mapping impl: input.cpp — translates SDL events to state changes (quit, resize, spawn cube/pyramid).

Build

Prereqs: SDL2 development headers installed and pkg-config available.

  • You can install the SDL2 development headers on Linux with:
sudo apt update
sudo apt install libsdl2-dev
make            # debug build to output/main
make run        # build and launch
make release    # optimized build
make asan       # debug with AddressSanitizer

If you don't use make:

mkdir -p output && g++ -std=c++17 -Wall -Wextra -g \
  $(pkg-config --cflags sdl2) -I. -Isrc \
  $(find src -name '*.cpp' -print) \
  -o output/main \
  $(pkg-config --libs sdl2)
./output/main

Controls

  • Esc: Quit
  • c or 1: Spawn cube
  • p or 2: Spawn pyramid

Rotation also animates with configured per-axis speeds in main.cpp.

Notes

  • Window is resizable; resizes update the projection viewport.
  • Event handling occurs once in the main loop; rendering callback is pure draw.
  • Projection guards extremely small denominators to avoid infinities near the camera.
  • To stop the 3d objects from rotating, set the rotation speed for all axis to 0.
  • To adjust the starting angle of the objects, change the angle X, Y and Z in main.cpp.

About

SDL2-based wireframe demo that rotates and projects simple 3D primitives (cube, pyramid) to 2D.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published