An SDL 2 sprite sheet generator


#1

In the past, I had a sprite sheet generator that was written in Java. I decided to have a crack at converting it to C (avec SDL2). The code can be found here:

It’s a bit rough and ready, but it gets the job done. It only creates one sheet and will begin rejecting images if it can’t fit anymore into the atlas. It outputs 1 PNG file and 1 JSON file with the data. It’s rather easy to compile and run:

Compile:

gcc src/atlas.c -o atlas sdl2-config --libs -lSDL2_image libpng-config --ldflags -g -lefence

Run:

./atlas -size <size> -dir <dir> -padding <padding>

Example:

./atlas -size 2048 -dir “/home/user/Project/project/gfx” -padding 1

Here’s an example output image:

And the corresponding JSON data:

https://www.parallelrealities.co.uk/downloads/tutorials/sdl2/atlas.json

I might write a full tutorial as to how it all works in the future, but for now I thought peeps might like to see the code. Hopefully it’ll be of use to those who like to work with C and SDL2. And those who are just curious :slight_smile: