SDL_image built with Zig.
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-10-16 10:55:13 -06:00
.github/workflows Switch SDL dependency to allyourcodebase's package 2026-08-05 22:41:47 -06:00
.gitattributes Enforce correct line endings on Windows 2025-04-05 22:39:05 -06:00
.gitignore Upgrade to SDL_image 3.4.2 2026-04-13 16:03:37 -06:00
build.zig Add missing option for ANI cursors 2026-09-07 12:54:54 -06:00
build.zig.zon Depend on SDL 1.0.6+3.4.18 2026-10-16 10:55:13 -06:00
LICENSE.txt Add a basic build.zig 2024-10-20 22:03:15 -06:00
README.md Add import/build instructions to the README 2026-08-23 17:31:03 +03:00

SDL_image

This is SDL_image packaged for Zig.

To use SDL_image along with SDL, do the following in the project you want them in:

  1. zig fetch both projects to save the dependencies to your build.zig.zon:
zig fetch --save git+https://github.com/allyourcodebase/SDL
zig fetch --save git+https://github.com/allyourcodebase/SDL_image
  1. Then do this in build.zig:
// build.zig
// ...
    const sdl_dep = b.dependency("sdl", .{
        .optimize = optimize,
        .target = target,
    });
    const sdl_lib = sdl_dep.artifact("SDL3");
    exe.root_module.linkLibrary(sdl_lib);

    const sdl_image_dep = b.dependency("SDL_image", .{
        .optimize = optimize,
        .target = target,
    });
    const sdl_image_lib = sdl_image_dep.artifact("SDL3_image");
    exe.root_module.linkLibrary(sdl_image_lib);

    const translate_c = b.addTranslateC(.{
        .root_source_file = b.addWriteFiles().add("stub.h",
            \\#include <SDL3/SDL.h>
            \\#include <SDL3_image/SDL_image.h>
        ),
        .target = target,
        .optimize = optimize,
    });
    translate_c.addIncludePath(sdl_lib.getEmittedIncludeTree());
    translate_c.addIncludePath(sdl_image_lib.getEmittedIncludeTree());
    exe.root_module.addImport("sdl-bundle", translate_c.createModule());
// ...

This will bundle SDL and SDL_image in a single module and allow cross-using the objects between the two libraries.

  1. Finally, you can use the two libraries like this in your project:
const sdl = @import("sdl-bundle");

const surface = sdl.IMG_Load("foo.png");
const texture = sdl.SDL_CreateTextureFromSurface(renderer, surface);