Quick Start
Get your first Cub3D scene running in just a few steps.Before starting, ensure you’ve completed the Installation Guide and have all dependencies installed.
Build and Run
Build the Project
cub3d.The Makefile (
Makefile:27-29) automatically builds both MiniLibX and Libft before compiling the main project.Available Example Maps
Themaps/ directory contains several example scenes:
COME.cub
Minimal 3x3 test map - perfect for quick testing
DOOMGUY.cub
Larger maze-like environment with DOOM-themed textures
DOOMSLAYER.cub
Complex layout for exploring raycasting effects
Engel.cub
Another themed environment to explore
Controls
Once the window opens, use these controls to navigate the 3D environment:Movement
The controls are defined incub3d.h:38-41 and implemented in utils5.c:29-46:
Forward
W key - Move forward in the direction you’re facing
Backward
S key - Move backward
Strafe Left
A key - Move left (perpendicular to facing direction)
Strafe Right
D key - Move right (perpendicular to facing direction)
Camera Rotation
Rotate Left
Left Arrow key - Rotate camera counterclockwise
Rotate Right
Right Arrow key - Rotate camera clockwise
System
Exit
ESC key - Close the window and exit the program (
utils5.c:32)What to Expect
When you run Cub3D, here’s what happens behind the scenes:1. Window Creation
The engine creates a window at 1732x1000 resolution (cub3d.h:30-31):
2. Map Parsing
The program reads your.cub file (main.c:83-90) and:
- Validates the map format
- Loads texture files (XPM format)
- Parses floor and ceiling RGB colors
- Finds the player starting position and direction
3. Raycasting Initialization
The raycasting engine initializes (main.c:51-72):
- Sets player position based on map spawn point
- Configures direction and plane vectors for the camera
- Loads all four wall textures into memory
- Creates the rendering image buffer
4. Real-time Rendering Loop
The main rendering loop (raycasting.c:102-127) executes every frame:
The engine casts 1732 rays per frame (one for each horizontal pixel), uses DDA to find wall intersections, and renders textured wall slices.
Visual Output
Rendering Components
- Ceiling - Solid color defined by
Cin the map file - Walls - Textured using XPM images based on wall orientation:
- North-facing walls use the
NOtexture - South-facing walls use the
SOtexture - East-facing walls use the
EAtexture - West-facing walls use the
WEtexture
- North-facing walls use the
- Floor - Solid color defined by
Fin the map file
Example: COME.cub
Let’s examine the minimal test map (maps/COME.cub):
- 3x3 enclosed room with walls on all sides
- Player spawns at center facing North (
N) - Floor color: RGB(220, 100, 0) - orange
- Ceiling color: RGB(225, 30, 0) - red
- Textures: Different XPM files for each direction
Performance Tips
Optimization
The Makefile compiles with
-O3 optimization for maximum performance. On modern hardware, you should achieve 60+ FPS at 1732x1000 resolution.Common Issues
Window doesn't open
Window doesn't open
Check that:
- X11 is running (
echo $DISPLAYshould show:0or similar) - You have permission to create windows
- No firewall is blocking X11 connections
Texture not found errors
Texture not found errors
The map file references XPM texture files that must exist in the same directory as the executable or use absolute paths.
Program crashes on startup
Program crashes on startup
Common causes:
- Invalid map format - Map must be enclosed by walls (1s)
- Missing player spawn - Must have exactly one N/S/E/W in the map
- Invalid RGB values - Colors must be 0-255
cub3d.h:42-66.Controls not responding
Controls not responding
Ensure:
- The Cub3D window has focus (click on it)
- You’re using the correct keys (WASD + Arrow keys)
- Your keyboard layout is standard US/QWERTY
cub3d.h:18 and utils5.c:29-46).Next Steps
Create Custom Maps
Learn how to design your own
.cub map filesUnderstanding Raycasting
Dive deep into the rendering algorithm
Texture Creation
Create custom XPM textures for your walls
Code Architecture
Explore the codebase structure and key functions
Experiments to Try
Change Starting Position
Move the player spawn point (
N, S, E, or W) to a different location in the map grid.The raycasting algorithm runs at
raycasting.c:102-127, with DDA implementation at raycasting.c:15-66. Understanding these functions is key to customizing the rendering behavior.