From cd236e8df75e2e7ebdce4fc1ed5504b867bdacfc Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Sun, 8 Jan 2023 18:18:26 -0700 Subject: [PATCH] glfw: README: update usage example Signed-off-by: Stephen Gutekanst --- libs/glfw/README.md | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/libs/glfw/README.md b/libs/glfw/README.md index 3179d036..8d6df019 100644 --- a/libs/glfw/README.md +++ b/libs/glfw/README.md @@ -102,17 +102,29 @@ Now in your code you may import and use GLFW: ```zig const glfw = @import("glfw"); +/// Default GLFW error handling callback +fn errorCallback(error_code: glfw.Error, description: [:0]const u8) void { + std.log.err("glfw: {}: {s}\n", .{ error_code, description }); +} + pub fn main() !void { - try glfw.init(.{}); + glfw.setErrorCallback(errorCallback); + if (!glfw.init(.{})) { + std.log.err("failed to initialize GLFW: {?s}", .{glfw.getErrorString()}); + std.process.exit(1); + } defer glfw.terminate(); // Create our window - const window = try glfw.Window.create(640, 480, "Hello, mach-glfw!", null, null, .{}); + const window = glfw.Window.create(640, 480, "Hello, mach-glfw!", null, null, .{}) orelse { + std.log.err("failed to create GLFW window: {?s}", .{glfw.getErrorString()}); + std.process.exit(1); + }; defer window.destroy(); // Wait for the user to close the window. while (!window.shouldClose()) { - try glfw.pollEvents(); + glfw.pollEvents(); } } ```