17 Rendering: Overview
This walkthrough covers the main rendering pipeline entry points, core interfaces, and key data structures used in DOOM’s software renderer. You’ll see how view setup, BSP traversal, wall and floor drawing, and video I/O fit together to render each frame.
r_main.c
R_Init
: sets up the game’s rendering system by initializing all required rendering components and data structures.
(Lines 773–784)R_SetupFrame
: configures the view parameters from the active player’s state before drawing begins.
(Lines 830–839)R_RenderPlayerView
: handles rendering a complete frame from the player’s perspective, coordinating the drawing of the 3D world while ensuring network updates happen throughout the process.
(Lines 868–898)
r_main.h
- Exposes the main rendering API:
R_Init
initializes the rendererR_RenderPlayerView
draws each frameR_SetViewSize
updates the viewport dimensions
(Lines 157–166)
Next we’ll look at r_defs.h
, which defines the data structures used by DOOM’s software renderer.
r_defs.h
Defines the foundational rendering data structures and constants: - vertex_t
, line_t
, seg_t
, node_t
: BSP geometry - drawseg_t
: deferred wall segments - patch_t
: column‐based textures - vissprite_t
: visible objects - visplane_t
: floor/ceiling spans
p_setup.c
P_LoadVertexes
: converts raw map vertices into fixed-point 2D coordinates
(Lines 144–148)P_LoadSectors
: reads sector data from the WAD file, setting heights, textures, and lighting insector_t
(Lines 247–251)
r_plane.c
R_FindPlane
: groupsvisplane_t
entries by height, picnum, and lightlevel
(Lines 231–236)
r_bsp.h
Handles BSP tree traversal for finding visible walls: - R_RenderBSPNode
traverses the tree - R_ClearClipSegs
and R_ClearDrawSegs
manage clipping and wall segment lists
r_plane.h
R_DrawPlanes()
: renders all floor and ceiling planes
(Lines 64–67)
r_draw.h
R_DrawColumn()
: renders wall columns
R_DrawFuzzColumn()
: spectre/invisibility effect
(Lines 46–51)
r_segs.c
R_StoreWallRange
: records a horizontal wall segment for later rendering
(Lines 374–378)
17.0.1 R_StoreWallRange
summary
Prepares a wall segment for rendering by:
- Computing view-relative distances/angles
- Setting up
drawseg
record - Handling:
- Single-sided walls:
midtexture
and silhouette - Double-sided walls: top/bottom textures, partial silhouettes
- Single-sided walls:
- Texture offsets & lighting
- Floor/ceiling visibility
- Sprite clipping prep
r_data.h
R_InitData
: loads and caches WAD textures and flats
(Lines 1–8)
R_InitTranslationTables
: builds palette translation tables
(Lines 40–42)
r_draw.h
- Prototype of
R_InitTranslationTables
(Lines 96–98)
r_sky.h
R_InitSkyMap
: rebuilds angle→sky mapping for sky drawing
(Lines 6–9 and declaration at line 41)
v_video.h
And that’s the overview of DOOM’s renderer – from initialization through BSP traversal to final output. Each component works together in a carefully designed pipeline to create DOOM’s distinctive visuals.