cub3D is a project inspired by the classic Wolfenstein 3D game engine. The goal is to build a basic 3D raycasting engine from scratch using the MiniLibX graphics library. It’s a great introduction to graphics programming, raycasting, and game loop logic, and serves as a foundation to understand how early 3D engines were built.
Using a .cub map file as input, cub3D renders a 3D environment from a first-person perspective. It includes texture rendering, player movement, collision detection, and keyboard input handling.
The project is entirely written in C and uses MiniLibX (a simple X11 wrapper) to handle window management and drawing.
- Raycasting (2D grid-based projection for 3D effect)
- Game loop and rendering cycle
- Texturing walls based on distance and perspective
- Real-time input handling (keyboard events)
- Map parsing and validation
- Efficient memory and error management in C
Clone the repo and run:
makeThis will:
- Compile all source files in
srcs/ - Create object files in the
obj/directory - Build the final executable:
cub3D
To clean up object files:
make cleanTo remove everything including the executable:
make fcleanTo recompile everything from scratch:
make reRun the program with a valid .cub map file:
./cub3D path/to/map.cubMake sure your map includes:
- Wall textures for each direction (N, S, E, W)
- Floor and ceiling colors (RGB)
- A valid layout (closed map, single player position)
- First-person 3D projection using raycasting
- Textured walls with directional rendering
- MiniMap overlay
- Basic keyboard input (WASD movement + rotation)
- Collision detection (no walking through walls)
- Window rendering using MiniLibX (Linux)
- Custom map parser and validation
MiniLibX(provided in the repo undermlx/)- Linux system with X11 (
libXext,libX11,libm)
NO ./textures/north.xpm
SO ./textures/south.xpm
WE ./textures/west.xpm
EA ./textures/east.xpm
F 220,100,0
C 225,30,0
111111
100001
1000N1
111111
Legend:
1= Wall0= Empty spaceN,S,E,W= Player starting position and direction
Feel free to fork, contribute, or use this as inspiration for your own 3D projects!
git clone https://github.com/cgermain78/cub3d.git
cd cub3D
make
./cub3D maps/example.cub