Port of basic_window_web from raylib (#210)

Port basic_window_web from raylib
This commit is contained in:
kukuen 2025-03-06 15:19:10 +01:00 committed by GitHub
parent 279bcc0a13
commit 1a9b848c06
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 59 additions and 0 deletions

View File

@ -107,6 +107,11 @@ pub fn build(b: *std.Build) !void {
.path = "examples/core/basic_window.zig",
.desc = "Creates a basic window with text",
},
.{
.name = "basic_window_web",
.path = "examples/core/basic_window_web.zig",
.desc = "Creates a basic window with text (web)",
},
.{
.name = "input_keys",
.path = "examples/core/input_keys.zig",

View File

@ -0,0 +1,54 @@
// A raylib-zig port of https://github.com/raysan5/raylib/blob/master/examples/core/core_basic_window_web.c
const rl = @import("raylib");
const builtin = @import("builtin");
const c = if (builtin.os.tag == .emscripten) @cImport({
@cInclude("emscripten/emscripten.h");
});
//----------------------------------------------------------------------------------
// Global Variables Definition
//----------------------------------------------------------------------------------
const screenWidth = 800;
const screenHeight = 450;
//------------------------------------------------------------------------------------
// Program main entry point
//------------------------------------------------------------------------------------
pub fn main() anyerror!void {
// Initialization
//--------------------------------------------------------------------------------------
rl.initWindow(screenWidth, screenHeight, "raylib-zig [core] example - basic window");
defer rl.closeWindow(); // Close window and OpenGL context
if (builtin.os.tag == .emscripten) {
c.emscripten_set_main_loop(@ptrCast(&updateDrawFrame), 0, true);
} else {
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
updateDrawFrame();
}
}
}
// Update and Draw one frame
fn updateDrawFrame() void {
// Update
//----------------------------------------------------------------------------------
// TODO: Update your variables here
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
rl.beginDrawing();
defer rl.endDrawing();
rl.clearBackground(rl.Color.white);
rl.drawText("Congrats! You created your first window!", 190, 200, 20, rl.Color.light_gray);
//----------------------------------------------------------------------------------
}