A Wolfenstein 3D-style FPS engine built from scratch in C using SDL2.
- GCC or Clang compiler
- SDL2 development libraries
- CMake 3.10+
On Ubuntu/Debian:
sudo apt-get install build-essential libsdl2-dev cmakeOn Fedora:
sudo dnf install gcc SDL2-devel cmakeOn Arch:
sudo pacman -S base-devel sdl2 cmakecmake -S . -B cmake-build-debug
cmake --build cmake-build-debugOr use your IDE (CLion, VS Code, etc.) to open the CMakeLists.txt
IMPORTANT: Run from the project root directory so the engine can find data/maps/test.map
Using the run script (easiest):
./run.shOr manually:
./cmake-build-debug/raycasterLoad a custom map:
./run.sh data/maps/your_map.maprm -rf cmake-build-debug
# or from your IDE: Build → Clean- W - Move forward
- S - Move backward
- A / Left Arrow - Rotate left
- D / Right Arrow - Rotate right
- M - Toggle mouse look
- TAB - Toggle minimap
- ESC - Quit
/src
/core - Game loop, timing, SDL initialization
/renderer - Raycasting algorithm, wall and sprite rendering
/input - Keyboard input handling
/map - Level data, collision detection, map loader
/player - Player movement and camera
/assets - Texture and sprite generation
/include - Header files
/data
/maps - Level files (.map format)
/textures - Texture assets (procedurally generated)
The engine uses raycasting to create a 3D perspective:
- For each vertical column on screen, cast a ray from the player
- Use DDA (Digital Differential Analysis) to find the first wall hit
- Calculate perpendicular distance to avoid fish-eye distortion
- Extract vertical texture slice and scale to wall height
- Apply side-based brightness for depth perception
- Store distance in Z-buffer for sprite rendering
- Calculate distance from player to each sprite
- Sort sprites from far to near (painter's algorithm)
- Transform sprite positions to camera space
- Project sprites to screen coordinates
- Draw sprites with transparency, checking Z-buffer for occlusion
This is the same technique used in Wolfenstein 3D (1992).