Game Engineering · Volume I

Do código aos pixels — C++20 e SDL3 desde o zero

Aprenda programação construindo a Arena, um jogo 2D desenvolvido capítulo por capítulo.

R$ 20,00 Planned price

Português (Brasil) · PDF · One-time purchase

In development — not yet available for purchase.

Book details

Raster Playground

A 512 × 512 canvas partitioned into storage tiles. Move the dirty rectangle and change tile size to see which tiles are candidates for updating.

4 of 16 tiles selected · 262,144 candidate bytes (RGBA8).

This is application-level invalidation, not a simulation of a GPU's internal tile memory. The dirty rectangle is conservative; actual work depends on the renderer.

Polygon Lab

Move a vertex or reverse the traversal order. The absolute area stays unchanged when winding is reversed, but the signed shoelace area changes sign.

123Signed area: 8830 px² · Absolute area: 8830 px² · Clockwise (screen coordinates).

In these screen coordinates, Y increases downwards, so positive signed area corresponds to clockwise winding. This experiment assumes a simple polygon.

RGB Playground

Predict the background color before changing a channel. Setting the draw color is not the same as clearing or presenting a frame.

#141820
SDL_SetRenderDrawColor(renderer, 20, 24, 32, 255);

Browser color model, not a native SDL3 render or display calibration.

Game Loop Inspector

Queue ordinary events, request close, then advance one operation at a time. Predict whether another frame will be presented.

pollclearpresentpoll · queued: 0 · frames: 0

Simplified sequential model: the close request is latched until the event queue drains. It does not model event arrival timing, GPU synchronization or frame duration.

Build Pipeline

Predict which artifact will exist when compilation or linking fails. Select a fault and advance one stage at a time.

  1. source
  2. preprocessed
  3. object
  4. executable
  5. running
source — hello.cpp
int main() { return 0; }

Conceptual native build, not a compiler. Compilation includes assembly in this model. A failed build does not necessarily remove artifacts from earlier builds; this experiment starts clean.

Resource Lifetime

Try drawing before creation and after destruction. Predict which resource remains live after each operation.

SDL videoabsentwindowabsentrendererabsent
No live resources.

Models the explicit cleanup order used in Arena, not every valid SDL sequence. Invalid operations are rejected without calling SDL. No actual addresses, allocation, failures or GPU synchronization are simulated.

Coordinate Explorer

Predict where the point moves when only y changes. Units are logical, not physical pixels.

xy(100, 160)

Rectangle Lab

Change width without moving the reference corner. Compare right, bottom and center.

right 148 · bottom 208 · center (124, 184)
SDL_FRect player{100.0f, 160.0f, 48.0f, 48.0f};

Geometry can extend outside the logical arena. The diagram includes this extra space; it does not simulate pixel coverage.

Draw Order

Swap the two opaque draw calls. The geometry stays identical.

At (135, 185): obstacle

Ideal opaque coverage, sampled inside the intersection. Clear precedes both calls; Present follows both.

Logical Presentation

Resize the output. Predict whether the empty space appears above and below or on the sides.

scale 0.8 · content 640 × 360 px · offsets (0, 60) px

Continuous geometric model; actual SDL output may round to pixel boundaries.

Future experiments

Physics Sandbox (fixed timestep and collision response) and Shader Playground (portable shader examples) are planned. They are not yet implemented.