Create a new GPU lesson for the forge-gpu project. Every GPU lesson uses
forge_scene.h for the rendering baseline (shadow map, Blinn-Phong lighting,
grid floor, sky gradient, FPS camera, UI). The lesson focuses entirely on its
subject matter, not rendering plumbing.
The user will provide:
- Number: two-digit lesson number (e.g. 02)
- Name: short kebab-case name (e.g. first-triangle)
- Description: what the lesson teaches
If any of these are missing, ask the user before proceeding.
Steps
- Start from a clean main branch:
Before creating any files, ensure we're working from the latest main:
```bash
git checkout main
git pull origin main
```
This avoids conflicts from stale branches and ensures the new lesson
builds on top of the latest project state.
- Determine what math is needed:
- Will this lesson use vectors (positions, colors, directions)?
- Will it use matrices (transformations, rotations)?
- Check if the math library (
common/math/forge_math.h) has what you need - If new math operations are needed, use
/dev-math-lessonto add them first
- Create the lesson directory:
lessons/gpu/$ARGUMENTS[0]-$ARGUMENTS[1]/
- Create main.c using the SDL callback architecture:
#define SDL_MAIN_USE_CALLBACKS 1before includes- Always use
forge_scene.hfor the rendering baseline. See the
forge-scene-renderer skill for the full API.
- Include required headers:
```c
#include <SDL3/SDL.h>
#include <SDL3/SDL_main.h>
#include <stddef.h> /* offsetof */
#include "math/forge_math.h"
#define FORGE_SCENE_IMPLEMENTATION
#include "scene/forge_scene.h"
```
SDL_AppInit— create GPU device, window, claim swapchain, allocate app_stateSDL_AppEvent— handle SDL_EVENT_QUIT (return SDL_APP_SUCCESS)SDL_AppIterate— per-frame GPU workSDL_AppQuit— cleanup in reverse order, SDL_free the app_state- Use
SDL_calloc/SDL_freefor app_state (not malloc/free) - Every SDL GPU call gets error handling with
SDL_Logand descriptive messages - Check every SDL function that returns
bool—SDL_SubmitGPUCommandBuffer,
SDL_SetGPUSwapchainParameters, SDL_AcquireGPUSwapchainTexture, etc. all
return false on failure. Log a descriptive error (include the function name)
and clean up or early-return. Never ignore a bool return value.
- Use
#define WINDOW_WIDTH 1280and#define WINDOW_HEIGHT 720(16:9).
All lessons use this standard size for consistent screenshots.
- No magic numbers in production/library code —
#defineorenum
everything. In lesson files, inline numeric literals are acceptable when
one-off demonstration values improve readability (e.g. vertex positions,
color components, sample coordinates)
- Extensive comments explaining why and purpose, not just what —
every pipeline setting, resource binding, and API call should have a brief
comment stating why that choice was made (e.g. why CULLMODE_NONE, why
TRIANGLELIST, why we push uniforms each frame). This is a recurring PR
review requirement.
- Use C99, matching SDL's own style
- Use math library types for all math operations (see "Using the Math Library" below)
- Create CMakeLists.txt:
```cmake
add_executable(NN-name WIN32 main.c)
target_include_directories(NN-name PRIVATE ${FORGE_COMMON_DIR})
target_link_libraries(NN-name PRIVATE SDL3::SDL3)
forge_target_assets(NN-name)
if(TARGET SDL3::SDL3-shared)
add_custom_command(TARGET NN-name POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:SDL3::SDL3-shared>
$<TARGET_FILE_DIR:NN-name>
VERBATIM
)
endif()
```
Create forge-assets.toml next to CMakeLists.txt declaring which
processed assets the lesson needs:
```toml
[assets]
dirs = [
"fonts/liberation_mono",
"models/ModelName = ModelName",
]
```