add small wrapper for raylib

This commit is contained in:
Fabien Freling 2022-04-07 14:12:23 +02:00
parent 749661ec36
commit 68df481b8a
5 changed files with 19 additions and 18 deletions

2
3rdparty/raygui vendored

@ -1 +1 @@
Subproject commit fd0d50bdb01e43f21b5ca33b9ef0f7f43f55e3f1 Subproject commit 865bb293764073c01e74314ef647464f1f10fd96

View file

@ -17,8 +17,9 @@ pub fn build(b: *std.build.Builder) void {
const ray = raylib.addRaylib(b, exe.target); const ray = raylib.addRaylib(b, exe.target);
exe.linkLibrary(ray); exe.linkLibrary(ray);
exe.addIncludeDir("./3rdparty/raylib/src"); exe.addIncludeDir("3rdparty/raylib/src");
exe.addIncludeDir("./3rdparty/raygui/src"); exe.addIncludeDir("3rdparty/raygui/src");
exe.addCSourceFile("src/raylib.c", &[_][]u8{});
exe.setBuildMode(mode); exe.setBuildMode(mode);
exe.install(); exe.install();

View file

@ -1,26 +1,20 @@
const std = @import("std"); const std = @import("std");
const ray = @cImport({ const r = @import("raylib.zig");
@cInclude("raylib.h");
});
const raygui = @cImport({
@cDefine("RAYGUI_IMPLEMENTATION", {});
@cInclude("raygui.h");
});
pub fn main() anyerror!void { pub fn main() anyerror!void {
std.log.info("All your codebase are belong to us.", .{}); std.log.info("All your codebase are belong to us.", .{});
ray.InitWindow(800, 450, "ray [core] example - basic window"); r.InitWindow(800, 450, "ray [core] example - basic window");
defer ray.CloseWindow(); defer r.CloseWindow();
while (!ray.WindowShouldClose()) { while (!r.WindowShouldClose()) {
ray.BeginDrawing(); r.BeginDrawing();
defer ray.EndDrawing(); defer r.EndDrawing();
ray.ClearBackground(ray.RAYWHITE); r.ClearBackground(r.RAYWHITE);
ray.DrawText("Congrats! You created your first window!", 190, 200, 20, ray.LIGHTGRAY); r.DrawText("Congrats! You created your first window!", 190, 200, 20, r.LIGHTGRAY);
if (raygui.GuiButton(raygui.Rectangle{ .x = 190, .y = 250, .width = 150, .height = 30 }, "Button")) { if (r.GuiButton(r.Rectangle{ .x = 190, .y = 250, .width = 150, .height = 30 }, "Button")) {
std.log.info("Button pressed", .{}); std.log.info("Button pressed", .{});
} }
} }

2
src/raylib.c Normal file
View file

@ -0,0 +1,2 @@
#define RAYGUI_IMPLEMENTATION
#include <raygui.h>

4
src/raylib.zig Normal file
View file

@ -0,0 +1,4 @@
pub usingnamespace @cImport({
@cInclude("raylib.h");
@cInclude("raygui.h");
});