mirror of
https://github.com/Not-Nik/raylib-zig.git
synced 2025-09-09 03:57:29 +00:00
Ported raylib example "text/text_format_text.c" (#141)
* Added example: text_format_text.zig * reverted autoformatting changes
This commit is contained in:
parent
58df62807f
commit
2176d37bcc
24
build.zig
24
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"));
|
||||
|
||||
@ -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",
|
||||
|
49
examples/text/text_format_text.zig
Normal file
49
examples/text/text_format_text.zig
Normal file
@ -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);
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user