glfw: README: update usage example

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2023-01-08 18:18:26 -07:00 committed by Stephen Gutekanst
parent e9ba368443
commit c244a7b72e

View file

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