Raycaster casts one ray per screen column through a fixed 10x10 map, samples a wall texture, applies distance shading, and presents the result as a compact first-person renderer.
The goal is simple: take a flat grid and make it feel like a navigable 3D space using DDA-style traversal, texture slicing, and SDL2 rendering.
| Ray traversal | DDA-style grid stepping across a fixed 10x10 map. |
| Textured walls | One vertical texture slice is rendered per screen column. |
| Depth shading | Distance-based brightness falloff creates stronger depth cues. |
| Mouse look | Relative mouse movement rotates the camera. |
| Collision | Keyboard movement checks the map before moving into a cell. |
| Focused controls | The cursor is hidden and SDL relative mouse mode is enabled. |
| Layer | Used for |
|---|---|
C |
Core loop, movement, raycasting, and rendering logic. |
SDL2 |
Window, renderer, input events, cursor, and relative mouse mode. |
SDL2_image |
Loading the PNG wall texture. |
SDL2_ttf |
Included in the SDL header setup for project consistency. |
libm |
Trigonometry and distance math. |
.
|-- main.c # Raycasting loop, movement, input, texture slicing, rendering
|-- headers.h # SDL includes and fixed 10x10 map data
|-- backrooms.png # Wall texture
`-- prot # Existing compiled/development artifact
Install dependencies on Ubuntu/Debian:
sudo apt install build-essential libsdl2-dev libsdl2-image-dev libsdl2-ttf-devCompile from the repository root:
gcc main.c -o raycaster -lSDL2 -lSDL2_image -lSDL2_ttf -lm./raycasterRun from the repository root so backrooms.png loads correctly.
| Input | Action |
|---|---|
| Mouse movement | Rotate view |
| Up arrow | Move forward |
| Down arrow | Move backward |
| Left arrow | Strafe left |
| Right arrow | Strafe right |
| Window close | Quit |
The map is a fixed 10x10 integer grid in headers.h, where 1 means wall and 0 means walkable space.
For every horizontal pixel column, the renderer:
- Computes a ray angle from the player angle and field of view.
- Steps through the grid until the ray hits a wall cell.
- Calculates the wall hit distance.
- Chooses the matching texture column.
- Draws a scaled vertical slice with distance-based brightness.
That combination turns the flat map into a first-person view while keeping the implementation small and readable.
| Limitation | Current state |
|---|---|
| Map data | Hard-coded in headers.h. |
| Debug tools | No minimap or debug overlay yet. |
| Texture projection | Simple texture sampling and distance scaling. |
| Window size | Assumes a 1280x720 render target. |