Skip to content

SDL3 exporter

Output

Packrat writes one generated C source file and one image per atlas page. The source uses SDL3 and SDL3_image types and includes atlas page loading, frame lookup, draw, and unload helpers.

Integrate

Compile the source with SDL3 and SDL3_image. Create an SDL3 renderer, call the generated packrat_sdl3_<stem>_load, find frames with packrat_sdl3_<stem>_find, and use the generated draw helper. Unload the atlas before destroying the renderer.

Keep the generated image in the directory passed to the loader. The metadata includes original frame size and trim offsets so trimmed frames can be drawn at a stable position.

Minimal program

This assumes the export base name is atlas and the generated source is included for a quick test. Replace player_0001 with a frame name that exists in your atlas:

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

int main(void) {
    SDL_Init(SDL_INIT_VIDEO);
    SDL_Window *window = SDL_CreateWindow("Packrat atlas demo", 800, 600, 0);
    SDL_Renderer *renderer = SDL_CreateRenderer(window, NULL);
    PackratSDL3_atlas atlas = {0};
    if (!packrat_sdl3_atlas_load(&atlas, renderer, ".")) return 1;

    const PackratSDL3_atlasFrame *frame =
        packrat_sdl3_atlas_find("player_0001", -1);
    bool running = true;
    while (running) {
        SDL_Event event;
        while (SDL_PollEvent(&event))
            if (event.type == SDL_EVENT_QUIT) running = false;
        SDL_SetRenderDrawColor(renderer, 30, 35, 45, 255);
        SDL_RenderClear(renderer);
        packrat_sdl3_atlas_draw(renderer, &atlas, frame, 400, 300,
            0.0, 2.0f, 2.0f, SDL_FLIP_NONE);
        SDL_RenderPresent(renderer);
    }

    packrat_sdl3_atlas_unload(&atlas);
    SDL_DestroyRenderer(renderer); SDL_DestroyWindow(window);
    SDL_Quit();
    return 0;
}

Packrat documentation