Draw Wall Function Step-by-Step

Wall Rendering Process
Wall Height
Start Y
End Y
Texture

Parameters

Constants:

WIDTH = 800 (screen width) HEIGHT = 600 (screen height) Texture Height = 64

Function Breakdown:

1. Calculate Wall Height

info.wall_height = (BLOCK / dist) * (WIDTH / 2);

This creates perspective: closer walls (smaller dist) appear taller. The (WIDTH / 2) factor scales the wall to screen proportions.

2. Calculate Start Y Position

info.start_y = (HEIGHT - info.wall_height) / 2;

Centers the wall vertically on screen. If wall is 400px tall on 600px screen, start_y = (600-400)/2 = 100.

3. Clamp Start Y (Screen Bounds)

if (info.start_y < 0) info.start_y = 0;

Prevents drawing above screen when wall is very close (very tall).

4. Calculate End Y Position

info.end_y = info.start_y + info.wall_height;

Simple addition to find where wall ends.

5. Clamp End Y (Screen Bounds)

if (info.end_y > HEIGHT) info.end_y = HEIGHT;

Prevents drawing below screen when wall is very close.

6. Calculate Texture Step

info.step = (float)info.tex->height / info.wall_height;

How much texture to advance per screen pixel. If texture is 64px and wall is 320px on screen, step = 64/320 = 0.2.

7. Calculate Initial Texture Position

info.tex_pos = (info.start_y - HEIGHT/2 + info.wall_height/2) * info.step;

Starting position in texture coordinates, accounting for wall centering and clipping.