{"id":21040718,"url":"https://github.com/l-briand/raylib-zig-bindings","last_synced_at":"2025-05-15T16:33:24.222Z","repository":{"id":241503431,"uuid":"805335516","full_name":"L-Briand/raylib-zig-bindings","owner":"L-Briand","description":"One to one translation of raylib.h, rlgl.h, rcamera.h and raygui.h files in zig. Build tools to compile raylib from source with simple zon dependency.","archived":false,"fork":false,"pushed_at":"2024-07-27T09:16:17.000Z","size":96,"stargazers_count":13,"open_issues_count":1,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-03T11:43:45.335Z","etag":null,"topics":["raygui","raylib","raylib-binding","zig"],"latest_commit_sha":null,"homepage":"","language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"zlib","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/L-Briand.png","metadata":{"files":{"readme":"README.MD","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-24T11:09:22.000Z","updated_at":"2025-01-01T19:22:12.000Z","dependencies_parsed_at":"2024-05-28T20:31:32.910Z","dependency_job_id":"7e37ad33-7759-4583-a40e-86b1683b363d","html_url":"https://github.com/L-Briand/raylib-zig-bindings","commit_stats":null,"previous_names":["l-briand/raylib-zig-bindings"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/L-Briand%2Fraylib-zig-bindings","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/L-Briand%2Fraylib-zig-bindings/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/L-Briand%2Fraylib-zig-bindings/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/L-Briand%2Fraylib-zig-bindings/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/L-Briand","download_url":"https://codeload.github.com/L-Briand/raylib-zig-bindings/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254377462,"owners_count":22061141,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["raygui","raylib","raylib-binding","zig"],"created_at":"2024-11-19T13:47:46.648Z","updated_at":"2025-05-15T16:33:23.911Z","avatar_url":"https://github.com/L-Briand.png","language":"Zig","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Raylib Zig Bindings\n\n1. One to one translation of\n   [raylib.h](https://github.com/raysan5/raylib/blob/master/src/raylib.h),\n   [rlgl.h](https://github.com/raysan5/raylib/blob/master/src/rlgl.h),\n   [rcamera.h](https://github.com/raysan5/raylib/blob/master/src/rcamera.h) and\n   [raygui.h](https://github.com/raysan5/raygui/blob/master/src/raygui.h) files in zig\n2. Build tools to compile raylib from source with simple zon dependency.\n\n- Raylib version `5.0`\n- Raygui version `4.0`\n- Zig version`0.13.0`\n\n# TLDR\n\n[Sample project here](https://github.com/L-Briand/raylib-zig-bindings-sample) using what's described below\n\n# Projects using this\n\n- https://github.com/Srekel/tides-of-tabletop\n\n# Setting up a project\n\nYou'll need raylib and raygui sources with the correct version:\n\n```bash\ngit clone --depth 1 --branch 5.0 https://github.com/raysan5/raylib.git\ngit clone --depth 1 --branch 4.0 https://github.com/raysan5/raygui.git\n```\n\nCreate a `build.zig.zon` file and use this project as dependency.\n\n```zon\n.{\n    .name = \"game\",\n    .version = \"0.0.0\",\n\n    .dependencies = .{\n        .@\"raylib-zig-bindings\" = .{\n            .url = \"https://github.com/L-Briand/raylib-zig-bindings/releases/download/1.1.0/release.tar.gz\",\n            .hash = \"122096dfc8994542d786f21d12806a9bb9bb388d3f731aa03b0cacda0f5c48de2b5c\",\n        }\n    },\n\n    .paths = .{\n        \"\",\n    },\n}\n```\n\nCreate a `build.zig` file looking like this:\n\n```zig\nconst std = @import(\"std\");\n// Import the project from zon file.\nconst rlzb = @import(\"raylib-zig-bindings\");\n\npub fn build(b: *std.Build) !void {\n    // Default zig setup\n    const target = b.standardTargetOptions(.{});\n    const optimize = b.standardOptimizeOption(.{});\n\n    const exe = b.addExecutable(.{\n        .name = \"game\",\n        .root_source_file = b.path(\"src/main.zig\"),\n        .target = target,\n        .optimize = optimize,\n    });\n\n    // Adding rlzb binding files for us to use in the main.zig file.\n    const bindings = b.dependency(\"raylib-zig-bindings\", .{\n        .target = target,\n        .optimize = optimize,\n    });\n    exe.root_module.addImport(\"rlzb\", bindings.module(\"raylib-zig-bindings\"));\n\n    // Compiling raylib with main.zig\n    // You can select which raylib C file to add in the third parameter\n    var setup = try rlzb.Setup.init(b, .{ .cwd_relative = \"raylib/src\" }, .{});\n    defer setup.deinit();\n\n    // This line copy the raygui.h file into raylib/src to build with it.\n    try setup.addRayguiToRaylibSrc(b, .{ .cwd_relative = \"raygui/src/raygui.h\" });\n\n    // If you have some raylib's C #define requirements that need to be at build time. \n    // You can set them here:\n    // setup.setRayguiOptions(b, exe, .{});\n    // setup.setRCameraOptions(b, exe, .{});\n    // setup.setRlglOptions(b, exe, .{});\n\n    // Note: \n    // Some target needs specific opengl api version (RlglOption). \n    // For example linux .platform = DRM requires opengl_es2\n    // If you do not uncomment the setup.setRlglOptions above.\n    // It will add it automatically when linking.\n\n    // Build specific for platform.\n    switch (target.result.os.tag) {\n        .windows =\u003e try setup.linkWindows(b, exe),\n        .macos =\u003e try setup.linkMacos(b, exe),\n        .linux =\u003e try setup.linkLinux(b, exe, .{ .platform = .DESKTOP, .backend = .X11 }),\n        else =\u003e @panic(\"Unsupported os\"),\n    }\n\n    // Add everything to the exe.\n    setup.finalize(b, exe);\n\n    // Default zig build run command setup\n    b.installArtifact(exe);\n    const run_cmd = b.addRunArtifact(exe);\n    run_cmd.step.dependOn(b.getInstallStep());\n    if (b.args) |args| {\n        run_cmd.addArgs(args);\n    }\n    const run_step = b.step(\"run\", \"Run the app\");\n    run_step.dependOn(\u0026run_cmd.step);\n}\n```\n\nAnd create a `src/main.zig` file. This is the translation\nof [raygui code sample](https://github.com/raysan5/raygui/tree/master?tab=readme-ov-file#code-sample).\n\n```zig\nconst std = @import(\"std\");\n\nconst rlzb = @import(\"rlzb\");\nconst rl = rlzb.raylib;\nconst rg = rlzb.raygui;\n\npub fn main() !void {\n   rl.InitWindow(400, 200, \"raygui - controls test suite\");\n   defer rl.CloseWindow();\n   rl.SetTargetFPS(60);\n\n   var showMessageBox = false;\n\n   while (!rl.WindowShouldClose()) {\n      rl.BeginDrawing();\n      const style = rg.GuiGetStyle(\n            rg.GuiControl.DEFAULT.toCInt(),\n            rg.GuiDefaultProperty.BACKGROUND_COLOR.toCInt(),\n      );\n      rl.ClearBackground(rl.GetColor(@bitCast(style)));\n\n      if (rg.GuiButton(rl.Rectangle.init(24, 24, 120, 30), \"#191#Show Message\") \u003e 0)\n         showMessageBox = true;\n\n      if (showMessageBox) {\n         const bounds = rl.Rectangle.init(85, 70, 250, 100);\n         const result = rg.GuiMessageBox(bounds, \"#191#Message Box\", \"Hi! This is a message!\", \"Nice;Cool\");\n         if (result \u003e= 0) showMessageBox = false;\n      }\n\n      rl.EndDrawing();\n   }\n\n   return;\n}\n```\n\nThen run `zig build run`. You should see a window popping up.\n\n![Raygui window](./raygui_screenshot.png)\n\nIf you don't want to switch between raylib and raygui. You can create a struct with wanted `usingnamespace` inside.\n\n```zig \nconst rl = struct {\n    const rlzb = @import(\"rlzb\");\n    usingnamespace rlzb.raylib;\n    usingnamespace rlzb.rlgl;\n    usingnamespace rlzb.rcamera;\n    usingnamespace rlzb.raygui;\n};\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fl-briand%2Fraylib-zig-bindings","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fl-briand%2Fraylib-zig-bindings","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fl-briand%2Fraylib-zig-bindings/lists"}