glfw: README: update usage example
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
e9ba368443
commit
c244a7b72e
1 changed files with 15 additions and 3 deletions
18
README.md
18
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();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
|
Loading…
Add table
Reference in a new issue