cub3D is a small 3D rendering project built with MiniLibX. It recreates a first-person maze experience using classic raycasting: the player moves inside a 2D map while the engine projects textured walls into a 3D view.
The project focuses on parsing a configuration file, validating the map, loading textures, handling keyboard input, drawing the scene frame by frame, and managing memory correctly.
- Build a functional first-person 3D renderer using MiniLibX
- Parse and validate a
.cubconfiguration file - Load four wall textures and ceiling/floor colors
- Implement raycasting for wall projection
- Support player movement and rotation with collision handling
- Provide a minimap build target for easier navigation
- Keep memory management clean and leak-free
You wake up inside a maze-like map and explore it in first person. The world is represented by a 2D grid, but the renderer turns that grid into a 3D view by casting rays from the player position toward the walls.
- Move through the map without walking through walls
- Use the textures and colors defined in the
.cubfile - Navigate the environment from a first-person perspective
- W or ↑ - Move forward
- S or ↓ - Move backward
- A - Strafe left
- D - Strafe right
- ← - Rotate left
- → - Rotate right
- ESC - Exit the game
The project uses a .cub file that contains both rendering configuration and the map layout.
NO- Path to the north wall textureSO- Path to the south wall textureWE- Path to the west wall textureEA- Path to the east wall textureF- Floor color in RGB formatC- Ceiling color in RGB format
1- Wall0- Empty spaceN- Player start facing northS- Player start facing southE- Player start facing eastW- Player start facing west
- The file must have a
.cubextension - All required texture paths and colors must be present
- The map must contain exactly one player spawn position
- The map must be enclosed by walls
- Only valid map characters are allowed
- Empty lines and spacing are handled by the parser, but the final map must still be valid
NO textures/north_wall.xpm
SO textures/south_wall.xpm
WE textures/west_wall.xpm
EA textures/east_wall.xpm
F 220,100,0
C 225,30,0
111111
1000N1
101111
100001
111111
This example contains:
- Four wall textures
- Floor and ceiling colors
- A closed map
- One player spawn facing north
The renderer uses MiniLibX and a fixed-size window.
- Window size: 1920x1080
- Texture mapping: one texture per wall face
- Projection: raycasting with per-column wall rendering
- Floor and ceiling: solid colors drawn after the wall pass
- Minimap: available through the
bonusbuild target
- MiniLibX - Included in
inc/mlx/ - X11 libraries - Required by MiniLibX on Linux
- gcc - C compiler
- make - Build tool
makeThis builds the cub3D executable.
make bonusThis builds the project with the minimap enabled.
make- Build the projectmake clean- Remove object filesmake fclean- Remove object files and the executablemake re- Rebuild everything from scratchmake bonus- Build with the minimap flag
./cub3D [map_file.cub]./cub3D maps/test.cub
./cub3D maps/test2.cub- The program opens a graphical window and renders the maze in first person
- Movement is updated continuously while keys are held down
- The ESC key closes the window and frees resources
- When built with
make bonus, the minimap can be displayed
The program reports descriptive errors for common failure cases:
- Invalid argument count
- Wrong file extension
- Missing
.cubfile - Missing texture paths
- Missing floor or ceiling colors
- Invalid RGB values
- Invalid map characters
- Missing or duplicate player spawn positions
- Unclosed map geometry
The project is split into focused modules:
- main.c - Program entry point, initialization, and game loop setup
- cub3d.h - Main header with constants, structures, and function prototypes
- input_reader.c - Reads the
.cubconfiguration and extracts textures/colors - input_checker.c - Validates configuration input
- input_utils.c - Helpers for line parsing and string checks
- map_reader.c - Loads the map from the file
- map_reader_utils.c - Helpers for map allocation and reading
- map_checker.c - Validates map characters and closed geometry
- map_utils.c - Utility functions for line counting, flood fill, and spawn detection
- raycaster.c - Raycasting and wall projection
- draw.c - Drawing utilities and ceiling/floor rendering
- player.c - Player movement, rotation, and collision handling
- init_player.c - Player spawn initialization and key state setup
- minimap.c - Minimap rendering for the bonus build
- utils.c - General helpers
- utils_for_utils.c - Additional helper functions
- Language: C
- Compiler: gcc
- Flags:
-Wall -Wextra -Werror - Graphics Library: MiniLibX
- Window Size: 1920x1080
- Tile Size: 48 pixels
- Raycasting Method: DDA-style wall traversal
- Player Movement: forward/backward movement, strafing, and rotation
- Collision System: wall collision enabled by default
The renderer casts one ray per screen column. Each ray finds the nearest wall hit, computes the projected wall height, and draws the matching texture slice on screen.
Wall faces are mapped to the correct texture according to the direction of impact:
- North wall texture
- South wall texture
- East wall texture
- West wall texture
After the wall pass, the remaining background pixels are filled using the floor and ceiling RGB colors from the configuration file.
When compiled with make bonus, the project can also render a minimap that shows the local map area and the player position.
The repository includes test maps in the maps/ directory:
./cub3D maps/test.cub
./cub3D maps/test2.cubCreate a .cub file with the required texture paths, floor and ceiling colors, and a valid enclosed map.
Checklist:
- Provide all four wall textures
- Define both RGB colors
- Use one of
N,S,E, orWfor the spawn point - Keep the map fully surrounded by walls
- Avoid invalid characters
- The project uses a fixed window size rather than dynamic scaling
- Textures are loaded from the paths defined in the map file
- The player starts facing the direction encoded in the spawn tile
- Collision is enabled by default to prevent walking through walls
- The minimap is optional and controlled by the build flag
- No advanced lighting or shading effects
- No enemy or interaction system
- No animation system for movement
- No dynamic resolution scaling
opopov and silpaukn