Categories
Graphics Library
  • Github CLI
  • SSH
  • HTTPS
Clone Repo

DEPRECATED: This is no longer needed since Zig added specific C-pointer types for translated code. I recommend using C import directly. If there is any issue with the automatic translation process, you can make an issue on the main zig compiler repository and we can fix upstream.

Minimal zig wrapper over SDL2.

For now, the standard SDL naming conventions are used but these will be changed in the future to use zig namespacing.

The only difference between this package and @cImport(@cInclude("SDL.h")) is fixing and correcting single-pointer entries and completing macro definitions that are otherwise untranslatable.

Example

use @import("src/index.zig");

pub fn main() u8 {
    if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) != 0) {
        SDL_Log(c"failed to initialized SDL\n");
        return 1;
    }
    defer SDL_Quit();

    var renderer: *SDL_Renderer = undefined;
    var window: *SDL_Window = undefined;

    if (SDL_CreateWindowAndRenderer(640, 480, SDL_WINDOW_SHOWN, &window, &renderer) != 0) {
        SDL_Log(c"failed to initialize window and renderer\n");
        return 1;
    }
    defer SDL_DestroyRenderer(renderer);
    defer SDL_DestroyWindow(window);

    SDL_SetWindowTitle(window, c"zig-sdl");
    _ = SDL_SetRenderDrawColor(renderer, 0, 64, 128, 255);
    _ = SDL_RenderClear(renderer);
    _ = SDL_RenderPresent(renderer);

    SDL_Delay(3000);
    return 0;
}

Todo

  • Clean up remaining arguments to take single-item pointers and non-nullables where applicable.
  • Convert c_int return codes to bool where applicable.
  • Potentially namespace functions to sdl. instead of the current SDL_.
About
SDL2 bindings for Zig
Owner
tiehuis (User)
Last Commit
2019-05-09
Latest Release
Latest Release Date
Created
2018-07-17