raylib-zig/examples/core/basic_window_web.zig
kukuen 1a9b848c06
Port of basic_window_web from raylib (#210)
Port basic_window_web from raylib
2025-03-06 15:19:10 +01:00

55 lines
2.0 KiB
Zig

// 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);
//----------------------------------------------------------------------------------
}