Cub3D is a C project based on a raycasting rendering engine inspired by Wolfenstein 3D. It uses MLX42 for graphics and libft_v2 as a utility library.
This project was developed collaboratively by @alejandquintero and @lgandarillas.
Raycasting is a rendering technique that simulates a 3D environment based on a 2D map. It works by casting a ray for each vertical stripe of the screen, finding intersections with walls in the map, and drawing vertical lines accordingly. This approach was used in early 3D games like Wolfenstein 3D to create a pseudo-3D effect efficiently.
cub3d/
├── assets/ # Assets (demo GIF)
├── inc/ # Header files
│ ├── cub3d.h
│ ├── parsing.h
│ ├── raycasting.h
│ └── structs.h
├── libft_v2/ # Custom Libft (submodule)
├── MLX42/ # MLX42 graphics library (submodule)
├── mazes/ # Example .cub maps
├── src/ # Source files
│ ├── parsing/ # Maze parsing, validation
│ ├── raycasting/ # Movement, rendering, raycasting
│ ├── free.c # Memory cleanup
│ ├── init.c # Struct initialization
│ └── main.c # Main entry point
├── textures/ # Texture images (.xpm42)
├── Makefile
└── README.md
Since the project uses submodules (libft_v2
and MLX42)
, clone it with:
git clone --recursive [email protected]:alejandquintero/cub3d.git
If you already cloned it without --recursive
:
git submodule update --init --remote
Before compiling, make sure you have the following installed:
sudo apt update && sudo apt install -y build-essential cmake libglfw3 libglfw3-dev libx11-dev xorg-dev
This will install:
gcc
,make
, etc.cmake
for MLX42.libglfw3
and X11 libraries for window management.
To compile the project, simply run:
make
If you want to compile in debug mode, use:
make debug
To clean up generated compilation files:
make clean # Removes object files (.o)
make fclean # Removes object files and the executable
make re # Recompile from scratch
After compiling, you can run Cub3D by passing a .cub map:
./cub3D mazes/42Example.cub
.cub maps define:
- Textures for North, South, East, West walls.
- Floor and Ceiling colors (RGB).
- The 2D layout of the maze.
Example Maze Snippet:
NO ./textures/north.xpm42
SO ./textures/south.xpm42
WE ./textures/west.xpm42
EA ./textures/east.xpm42
F 220,100,0
C 225,30,0
111111
100001
1000N1
100001
111111
- 1: Wall
- 0: Empty space
- N, S, E, W: Player starting position and direction
- W / S : Move forward / backward
- A / D : Strafe left / right
- ← / → : Rotate view
- ESC : Exit game