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(); } } ```