mirror of
https://github.com/Not-Nik/raylib-zig.git
synced 2025-09-09 03:57:29 +00:00
Port of basic_window_web from raylib (#210)
Port basic_window_web from raylib
This commit is contained in:
parent
279bcc0a13
commit
1a9b848c06
@ -107,6 +107,11 @@ pub fn build(b: *std.Build) !void {
|
|||||||
.path = "examples/core/basic_window.zig",
|
.path = "examples/core/basic_window.zig",
|
||||||
.desc = "Creates a basic window with text",
|
.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",
|
.name = "input_keys",
|
||||||
.path = "examples/core/input_keys.zig",
|
.path = "examples/core/input_keys.zig",
|
||||||
|
54
examples/core/basic_window_web.zig
Normal file
54
examples/core/basic_window_web.zig
Normal 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);
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user