Skip to content

Latest commit

 

History

30 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Raycaster

A first-person SDL2 raycasting experiment inspired by early 3D engines.

Language C SDL2 SDL2 Image Math

Features Build Controls Demo video


Overview

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.

Features

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.

Tech Stack

C SDL2 SDL2 image SDL2 ttf headers libm

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.

Project Structure

.
|-- 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

Build

Install dependencies on Ubuntu/Debian:

sudo apt install build-essential libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev

Compile from the repository root:

gcc main.c -o raycaster -lSDL2 -lSDL2_image -lSDL2_ttf -lm

Run

./raycaster

Run from the repository root so backrooms.png loads correctly.

Controls

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

Demo Video

Raycaster gameplay preview

How It Works

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:

  1. Computes a ray angle from the player angle and field of view.
  2. Steps through the grid until the ray hits a wall cell.
  3. Calculates the wall hit distance.
  4. Chooses the matching texture column.
  5. 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.

Current Limitations

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.

Built with C, SDL2, and ray-column math.

About

a raycasting engine built using c language and mathematical foundation

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages