← ziglang.inraylib-zigGitHub

Getting started

raylib-zig is a Zig package. You add it to your project, import the raylib module, and write a normal Zig program. The project on this page is built every time this site is built, so the steps are known to work.

What you need

sudo apt install libx11-dev libxext-dev libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev libgl-dev

1. Make a project

Make a folder for the project. Inside it, zig init --minimal writes a build.zig.zon and abuild.zig. You'll replace the build.zig in step 3.

mkdir basic_window && cd basic_window
zig init --minimal

2. Add raylib-zig

This downloads raylib-zig and records it in build.zig.zon under the name raylib_zig, with the commit and a hash of its contents:

zig fetch --save=raylib_zig git+https://github.com/algorisys-oss/raylib-zig-port

3. Write build.zig

The build gets the raylib module from the dependency and gives it to your program. Passing the target and optimize mode on to the dependency builds raylib the same way as your program.

const std = @import("std");

pub fn build(b: *std.Build) void {
    const target = b.standardTargetOptions(.{});
    const optimize = b.standardOptimizeOption(.{});

    const raylib_zig = b.dependency("raylib_zig", .{ .target = target, .optimize = optimize });

    const exe = b.addExecutable(.{
        .name = "basic_window",
        .root_module = b.createModule(.{
            .root_source_file = b.path("src/main.zig"),
            .target = target,
            .optimize = optimize,
            .imports = &.{.{ .name = "raylib", .module = raylib_zig.module("raylib") }},
        }),
    });
    b.installArtifact(exe);

    const run = b.addRunArtifact(exe);
    b.step("run", "Run the example").dependOn(&run.step);
}

4. Write src/main.zig

This is raylib's first example, basic window, in raylib-zig's Zig API. The names are raylib's, with the first letter in lower case. defercloses the window and ends each frame, so you can't forget to.

//! raylib [core] example - basic window
//!
//! Zig-API translation of examples/core/core_basic_window.c (raylib 6.2).
//! Example licensed under an unmodified zlib/libpng license.
//! Copyright (c) 2013-2026 Ramon Santamaria (@raysan5)

const rl = @import("raylib");

pub fn main() void {
    // Initialization
    const screen_width = 800;
    const screen_height = 450;

    rl.initWindow(screen_width, screen_height, "raylib [core] example - basic window");
    defer rl.closeWindow(); // Close window and OpenGL context

    rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second

    // Main game loop
    while (!rl.windowShouldClose()) { // Detect window close button or ESC key
        // Draw
        rl.beginDrawing();
        defer rl.endDrawing();

        rl.clearBackground(.ray_white);
        rl.drawText("Congrats! You created your first window!", 190, 200, 20, .light_gray);
    }
}

5. Build and run

zig build run

The first build compiles raylib too, so it takes a while. Later builds reuse it. Press Escape or close the window to quit.

Next