Skip to content

SDL3 ​

Packrat writes one C header for all pages. The generated code requires SDL3 and SDL3_image. Create a renderer before loading the atlas, and keep the page images in the directory passed to packrat_load.

c
#include <SDL3/SDL.h>
#include <SDL3_image/SDL_image.h>
#include "atlas.h"

void draw_example(SDL_Renderer *renderer) {
    Packrat_atlas atlas = {0};
    if (!packrat_load(&atlas, &packrat_atlas_definition, renderer, "assets")) return;
    const Packrat_frame *frame = packrat_find(&atlas, "player", -1);
    packrat_draw(renderer, &atlas, frame, 400, 300, 0, 2, 2, SDL_FLIP_NONE);
    // Present the renderer; unload when finished, before destroying it.
    packrat_unload(&atlas);
}
HelperUse
packrat_load(atlas, definition, renderer, directory)Create page textures; return false on failure
packrat_unload(atlas)Release textures
packrat_frame_at(atlas, index)Find a frame by its position in the frame list
packrat_find(atlas, name, index)Find a frame by name; a negative index selects the first match
packrat_find_animation(atlas, name)Return frames in order and their count
packrat_draw(renderer, atlas, frame, x, y, rotation, sx, sy, flip)Apply trim placement and transforms

A failed lookup returns NULL. Generated definitions are named packrat_<stem>_definition. You can include several generated SDL3 headers in one source file. Keep generated SDL2 and SDL3 headers in separate source files. SDL3 uses SDL_FRect and SDL_FPoint frame fields.

The draw position is the center of the original, untrimmed frame. Rotation is measured in degrees.

See Sources and outputs for frame names, trimming, and effect maps.

Packrat documentation