diff --git a/build.zig b/build.zig index 8a84dbf..6a92623 100755 --- a/build.zig +++ b/build.zig @@ -44,7 +44,7 @@ fn link( exe: *std.Build.Step.Compile, target: std.Build.ResolvedTarget, optimize: std.builtin.Mode, - options: Options + options: Options, ) void { const lib = getRaylib(b, target, optimize, options); @@ -104,7 +104,7 @@ fn getRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.buil .platform_drm = options.platform_drm, .shared = options.shared, .linux_display_backend = options.linux_display_backend, - .opengl_version = options.opengl_version + .opengl_version = options.opengl_version, }); const lib = raylib.artifact("raylib"); @@ -118,12 +118,15 @@ fn getRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.buil lib.step.dependOn(&gen_step.step); const raygui_c_path = gen_step.add("raygui.c", "#define RAYGUI_IMPLEMENTATION\n#include \"raygui.h\"\n"); - lib.addCSourceFile(.{ .file = raygui_c_path, .flags = &[_][]const u8{ - "-std=gnu99", - "-D_GNU_SOURCE", - "-DGL_SILENCE_DEPRECATION=199309L", - "-fno-sanitize=undefined", // https://github.com/raysan5/raylib/issues/3674 - }}); + lib.addCSourceFile(.{ + .file = raygui_c_path, + .flags = &[_][]const u8{ + "-std=gnu99", + "-D_GNU_SOURCE", + "-DGL_SILENCE_DEPRECATION=199309L", + "-fno-sanitize=undefined", // https://github.com/raysan5/raylib/issues/3674 + }, + }); lib.addIncludePath(raylib.path("src")); lib.addIncludePath(raygui_dep.path("src")); @@ -220,7 +223,7 @@ pub fn build(b: *std.Build) !void { .name = "3d_camera_first_person", .path = "examples/core/3d_camera_first_person.zig", .desc = "Simple first person demo", - }, + }, .{ .name = "2d_camera_mouse_zoom", .path = "examples/core/2d_camera_mouse_zoom.zig", @@ -252,6 +255,11 @@ pub fn build(b: *std.Build) !void { .path = "examples/textures/textures_background_scrolling.zig", .desc = "Background scrolling & parallax demo", }, + .{ + .name = "text_format_text", + .path = "examples/text/text_format_text.zig", + .desc = "Renders variables as text", + }, // .{ // .name = "models_loading", // .path = "examples/models/models_loading.zig", diff --git a/examples/text/text_format_text.zig b/examples/text/text_format_text.zig new file mode 100644 index 0000000..5ea8c40 --- /dev/null +++ b/examples/text/text_format_text.zig @@ -0,0 +1,49 @@ +// A raylib port of https://github.com/raysan5/raylib/blob/master/examples/text/text_format_text.c + +const rl = @import("raylib"); +const std = @import("std"); + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +pub fn main() anyerror!void { + // Initialization + //-------------------------------------------------------------------------------------- + const screenWidth = 800; + const screenHeight = 450; + + rl.initWindow(screenWidth, screenHeight, "raylib [text] example - text formatting"); + defer rl.closeWindow(); // Close window and OpenGL context + + // Set as 'const' for demonstration purposes, but would need to be 'var' once you actually update them to real values. + const score: i32 = 100020; + const hiscore: i32 = 200450; + const lives: i32 = 5; + + 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 + // Update + //---------------------------------------------------------------------------------- + // TODO: Update your variables here + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + rl.beginDrawing(); + defer rl.endDrawing(); + + rl.clearBackground(rl.Color.white); + + rl.drawText(rl.textFormat("Score: %08i", .{score}), 200, 80, 20, rl.Color.red); + + rl.drawText(rl.textFormat("HiScore: %08i", .{hiscore}), 200, 120, 20, rl.Color.green); + + rl.drawText(rl.textFormat("Lives: %02i", .{lives}), 200, 160, 40, rl.Color.blue); + + rl.drawText(rl.textFormat("Elapsed Time: %02.02f ms", .{rl.getFrameTime() * 1000}), 200, 220, 20, rl.Color.black); + //---------------------------------------------------------------------------------- + } +}