Skip to content

Pure C exporter ​

How it works ​

Packrat writes a C99 header containing read-only frame metadata and one image file for each atlas page. It does not load images, allocate textures, or draw; your engine or image library owns those tasks.

API ​

The generated header contains these declarations:

text
typedef struct PackratFrame {
    const char *name;
    uint32_t x, y, width, height;
    uint32_t original_width, original_height;
    int32_t offset_x, offset_y;
    int32_t index;
    uint8_t rotated;
} PackratFrame;

static const char packrat_sheet_N_image[] = "<image-file>";
static const uint32_t packrat_sheet_N_width = <page-width>;
static const uint32_t packrat_sheet_N_height = <page-height>;
static const PackratFrame packrat_sheet_N_frames[] = { /* frame records */ };
static const size_t packrat_sheet_N_frame_count = <frame-count>;

N is the one-based page number. x, y, width, and height are the packed image rectangle. original_width and original_height describe the logical frame. index is the source animation index, or -1 for a static frame. Group frames by name and sort by index when building an animation. offset_x is left-origin; offset_y is bottom-origin in this C format.

Integrate ​

Include the generated header, load the image named by its page constant, and sample the packed rectangle. Place the sampled pixels inside the original frame using the trim offsets:

c
#include "atlas.h"

/* Pseudocode: use the image API provided by your engine. */
const PackratFrame *frame = &packrat_sheet_1_frames[0];
ImageHandle image = load_image(packrat_sheet_1_image);
AtlasRect source = { frame->x, frame->y, frame->width, frame->height };
draw_image(image, source, frame->original_width, frame->original_height);
destroy_image(image);

ImageHandle, AtlasRect, and the image functions are placeholders for your engine's API. Use offset_x and offset_y for logical placement, converting offset_y to your renderer's coordinate convention when needed. Restore a rotated frame when rotated is nonzero. The generated data supplies metadata; it does not load or draw anything. Multipacks produce numbered header and image pairs.

Packrat documentation