A C raycasting project with MiniLibX, `.cub` parsing, textured walls, and player movement.
Raycasting • MiniLibX • Parsing • Textures • 42
cub3D is a project developed as part of the 42 curriculum.
This repository contains a small 3D engine written in C. It parses a .cub configuration file, validates texture paths, floor and ceiling colors, map layout, and player spawn, then opens a MiniLibX window and renders a textured maze with a raycasting pipeline.
This project focuses on:
- parsing and validating
.cubfiles - handling player movement and camera rotation
- rendering textured walls with DDA raycasting
- freeing allocated resources correctly on exit
Note: this README is based only on information that can be verified directly from this repository. The official subject PDF is not present here, so anything not visible in the codebase is intentionally left unclaimed.
- ✅ Parses
.cubfiles withNO,SO,WE,EA,F, andCentries - ✅ Validates texture extensions, file accessibility, and required configuration fields
- ✅ Validates map characters, closed walls, and single player spawn
- ✅ Renders textured walls with colored floor and ceiling
- ✅ Supports keyboard movement, rotation,
ESC, and window-close exit handling ⚠️ The current project code uses keyboard controls only; no mouse-look is implemented
Through this project, I worked on the following concepts:
- event handling with MiniLibX
- structured parsing of configuration files
- RGB parsing and conversion
- DDA raycasting
- texture sampling per rendered column
- collision checks and cleanup of allocated resources
Clone the repository and compile the project:
git clone git@github.com:Middle-555/Cub3D.git
cd Cub3D/cub3d
makeAvailable Makefile rules:
make
make exe
make clean
make fclean
make reRun the program with:
./cub3D <path/to/map.cub>Examples:
./cub3D maps/map/basique.cub
./cub3D maps/map/evolved.cub
./cub3D maps/map/manquecouleur.cubUsage notes:
- The code handles
W,A,S,Dfor movement. UPandDOWNmove forward and backward, whileLEFTandRIGHTrotate the camera.ESCand the window close button both trigger cleanup and exit.
.
├── README.md
└── cub3d/
├── Makefile
├── include/
│ ├── cub.h
│ └── minilibx-linux/
├── main.c
├── maps/
│ ├── map/
│ └── textures/
└── srcs/
├── gameplay/
├── minilibx/
├── parsing/
├── raycasting/
└── utils/
Structure details:
cub3d/include/: main project header and bundled MiniLibX headerscub3d/srcs/: main project source codecub3d/srcs/gameplay/: movement, rotation, exit hooks, and cleanupcub3d/srcs/parsing/:.cubparsing, validation, and game structure initializationcub3d/srcs/raycasting/: ray setup, DDA traversal, distance calculation, and textured column renderingcub3d/srcs/utils/libft/: locallibftused by the projectcub3d/maps/: sample valid and invalid maps plus XPM textures
This project follows the constraints that are visible in the repository itself:
- written in C
- structured as a 42
cub3Dproject - uses MiniLibX and a local
libft - includes explicit cleanup paths for textures, images, map data, window, and display resources
- stays within the scope of parsing a map file and rendering a simple textured 3D scene
The repository currently supports the following testing approach:
- build the project with the provided
Makefile - run the executable with valid sample maps such as
basique.cubandevolved.cub - run the executable with invalid sample maps to verify parser rejection paths
- review parsing branches for missing textures, invalid colors, invalid map characters, and missing player spawn
- run memory checks with Valgrind on a Linux environment
Suggested manual test commands:
make
./cub3D maps/map/basique.cub
./cub3D maps/map/manquecouleur.cubMemory checks:
valgrind --leak-check=full --show-leak-kinds=all ./cub3D maps/map/basique.cubTesting notes:
- The repository includes several invalid maps in
cub3d/maps/map/, such as missing colors, missing paths, invalid map structure, and missing player spawn cases.
This project helped me improve in the following areas:
- structuring a medium-sized C project around clear modules
- building a parser that rejects invalid input early
- understanding camera vectors, FOV, and per-column raycasting
- thinking more carefully about cleanup and resource ownership
Although the current repository already covers the core scope, several improvements could be considered:
- add mouse-based camera rotation
- make the build more portable across Linux and macOS environments
- extend the engine with bonus features such as a minimap or HUD
- strengthen automated validation with a dedicated parser test script
Middle
42 student