diff options
| author | andromeda <andromeda@lenovo> | 2026-06-12 19:03:28 +0200 |
|---|---|---|
| committer | andromeda <andromeda@lenovo> | 2026-06-12 19:03:28 +0200 |
| commit | d3a1fe476d6ce9cac90fea61d03f8158b2d09c0e (patch) | |
| tree | 637e2c65be1985314d6589681545e3412b6a7437 /main.zig | |
| parent | 3497d178379d34c604fd88aa41b8b6a8de6429bc (diff) | |
rgfw example
Diffstat (limited to 'main.zig')
| -rw-r--r-- | main.zig | 28 |
1 files changed, 27 insertions, 1 deletions
@@ -1,5 +1,31 @@ const std = @import("std"); +const rgfw = @import("rgfw.zig"); + +fn keyfunc (event: [*c]const rgfw.RGFW_event) callconv(.c) void { + if(event.*.key.value == rgfw.RGFW_keyEscape) { + rgfw.RGFW_window_setShouldClose(event.*.common.win, 1); + } +} pub fn main() !void { - std.debug.print("Hello World!\n", .{}); + const win: ?*rgfw.RGFW_window = rgfw.RGFW_createWindow("a window", 0, 0, 800, 600, rgfw.RGFW_windowCenter | rgfw.RGFW_windowNoResize | rgfw.RGFW_windowOpenGL); + _ = rgfw.RGFW_setEventCallback(rgfw.RGFW_keyPressed, keyfunc); + + var mouseX: i32 = 0; + var mouseY: i32 = 0; + + while(rgfw.RGFW_FALSE == rgfw.RGFW_window_shouldClose(win)) { + var event: rgfw.RGFW_event = undefined; + while(rgfw.RGFW_TRUE == rgfw.RGFW_window_checkEvent(win, &event)) { + _ = rgfw.RGFW_window_getMouse(win, &mouseX, &mouseY); + if(event.type == rgfw.RGFW_mouseButtonPressed and event.button.value == rgfw.RGFW_mouseLeft) { + std.debug.print("You clicked at x: {d}, y: {d}\n", .{mouseX, mouseY}); + } + } + if(rgfw.RGFW_TRUE == rgfw.RGFW_isMousePressed(rgfw.RGFW_mouseRight)) { + std.debug.print("The right mouse button was clicked at x: {d}, y: {d}\n", .{mouseX, mouseY}); + } + rgfw.RGFW_window_swapBuffers_OpenGL(win); + } + rgfw.RGFW_window_close(win); }
\ No newline at end of file |
