19 Rendering: Initialization and Frame Setup
This tour explores rendering initialization and frame setup in r_main.c, covering R_Init, R_SetupFrame, R_RenderPlayerView, R_SetViewSize, R_ExecuteSetViewSize, and R_AddPointToBox.
19.0.1 R_Init (r_main.c:773–794)
Initializes the renderer: - Sets up data tables (R_InitData, R_InitPointToAngle, R_InitTables) - Applies default view size (R_SetViewSize) - Initializes planes, lights, sky map, translation tables - Resets framecount
19.0.2 R_SetupFrame (r_main.c:829–863)
Prepares per-frame view state: - Assigns viewplayer - Computes viewx, viewy, viewangle (with offset) - Sets extralight, viewz, viewsin, viewcos - Manages fixedcolormap and walllights - Increments framecount and validcount
19.0.3 R_RenderPlayerView (r_main.c:871–898)
Drives the frame render: - Calls R_SetupFrame - Clears segmentation buffers: - R_ClearClipSegs - R_ClearDrawSegs - R_ClearPlanes - R_ClearSprites - Updates network events - Traverses BSP: R_RenderBSPNode - Draws planes: R_DrawPlanes - Renders masked objects: R_DrawMasked - Interleaves with NetUpdate checks
19.0.4 R_SetViewSize (r_main.c:658–665)
Defers view resizing: - Sets setsizeneeded flag - Stores desired block scale and detail shift for the next refresh
19.0.5 R_ExecuteSetViewSize (r_main.c:671–680)
Applies view parameters: - Computes scaledviewwidth, viewheight - Derives detailshift, viewwidth, centerx, centery - Calculates projection: projection = centerxfrac
19.0.6 Rendering Function Selection (r_main.c:702–708)
- Sets column and span functions:
colfunc,basecolfunc,fuzzcolfunc,transcolfunc,spanfunc
- Based on
detailshift(high vs. low detail)
19.0.7 Buffer and Sprite Setup (r_main.c:717–724)
- Initializes drawing buffer:
R_InitBuffer - Configures texture mappings:
R_InitTextureMapping - Sets
pspritescalefor player sprites
19.0.8 R_AddPointToBox (r_main.c:143–152)
Expands a bounding box to include a point (x, y): - Clamps box edges if the point is outside the current bounds
This completes the walk through of rendering initialization and frame setup in r_main.c.