I downloaded the header file of raygui manually, but it didn’t work. I get a error:
root@jiangbo:~/workspace/demo# zig build run
run
└─ run demo
└─ zig build-exe demo Debug native 1 errors
/root/workspace/demo/zig-cache/o/5204200a6170fd0d9018a4aabd4b699b/cimport.zig:7980:36: error: expected type 'usize', found '[*c]u8'
fileDataPtr += @as([*c]u8, @ptrFromInt(@sizeOf(c_int)));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
referenced by:
GuiLoadStyle: /root/workspace/demo/zig-cache/o/5204200a6170fd0d9018a4aabd4b699b/cimport.zig:1554:17
remaining reference traces hidden; use '-freference-trace' to see all reference traces
build.zig.zon file:
.{
.name = "demo",
.version = "0.0.0",
.dependencies = .{
.raylib = .{
.url = "https://github.com/raysan5/raylib/archive/ed9a6d862b9e31acaa59c6ffffd1f8aa398d54d8.tar.gz",
.hash = "12200b5a963e542a0d0d3a4b588e2410951c407c68ea44d98ae0572f3a48cb2fa516",
},
.raygui = .{
.path = "vendor/raygui", // contains the raygui.h
},
},
.paths = .{""},
}
build.zig:
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const exe = b.addExecutable(.{
.name = "demo",
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
});
const raylib_dep = b.dependency("raylib", .{
.target = target,
.optimize = optimize,
// .raygui = true,
});
exe.linkLibrary(raylib_dep.artifact("raylib"));
const raygui_dep = b.dependency("raygui", .{
.target = target,
.optimize = optimize,
});
exe.addIncludePath(raygui_dep.path(""));
b.installArtifact(exe);
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
}
raylib.zig:
pub usingnamespace @cImport({
@cInclude("raylib.h");
@cDefine("RAYGUI_IMPLEMENTATION", {});
@cInclude("raygui.h");
});
main.zig:
const std = @import("std");
const ray = @import("raylib.zig");
pub fn main() !void {
const screenWidth: c_int = 800;
const screenHeight: c_int = 450;
ray.InitWindow(screenWidth, screenHeight, "raylib [shapes] example");
defer ray.CloseWindow();
ray.SetTargetFPS(60);
while (!ray.WindowShouldClose()) {
// Update
// Draw
ray.BeginDrawing();
defer ray.EndDrawing();
ray.ClearBackground(ray.RAYWHITE);
const rec = ray.Rectangle{ .x = 600, .y = 40, .width = 120, .height = 20 };
_ = ray.GuiSliderBar(rec, "StartAngle", null, 0, -450, 450);
ray.DrawFPS(10, 10);
}
}
zig version: 0.12.0-dev.3076+6e078883e
github repo: GitHub - jiangbo/demo