Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/IridescenceTech/zglfw
A thin, idiomatic wrapper for GLFW. Written in Zig, for Zig!
https://github.com/IridescenceTech/zglfw
glfw opengl zig zig-package
Last synced: 3 months ago
JSON representation
A thin, idiomatic wrapper for GLFW. Written in Zig, for Zig!
- Host: GitHub
- URL: https://github.com/IridescenceTech/zglfw
- Owner: IridescenceTech
- License: other
- Created: 2020-09-17T18:03:48.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-07-24T16:13:02.000Z (6 months ago)
- Last Synced: 2024-11-02T19:06:08.435Z (3 months ago)
- Topics: glfw, opengl, zig, zig-package
- Language: Zig
- Homepage:
- Size: 368 KB
- Stars: 84
- Watchers: 5
- Forks: 12
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
zGLFW
A thin, idiomatic wrapper for GLFW. Written in Zig, for Zig!
# Why write a wrapper?
While Zig is PERFECTLY capable of simply `@cImport`ing glfw3.h and using it in your application, I think it lacks a lot of cleanliness and succinctness that can be expressed with Zig. I decided to write this wrapper to provide GLFW with a nicer interface, error handling options, and quality of life changes (for example `[]const u8` instead of `[*c]const u8`). It also uses nicely named constants in place of `#define`s.zGLFW is NOT 100% tested. I am happy to fix any errors that may arise, and I will accept contributions! Errors that arise from GLFW will be printed to `stderr`.
# Examples
```zig
const std = @import("std");
const glfw = @import("glfw");pub fn main() !void {
var major: i32 = 0;
var minor: i32 = 0;
var rev: i32 = 0;glfw.getVersion(&major, &minor, &rev);
std.debug.print("GLFW {}.{}.{}\n", .{ major, minor, rev });//Example of something that fails with GLFW_NOT_INITIALIZED - but will continue with execution
//var monitor: ?*glfw.Monitor = glfw.getPrimaryMonitor();try glfw.init();
defer glfw.terminate();
std.debug.print("GLFW Init Succeeded.\n", .{});var window: *glfw.Window = try glfw.createWindow(800, 640, "Hello World", null, null);
defer glfw.destroyWindow(window);while (!glfw.windowShouldClose(window)) {
if (glfw.getKey(window, glfw.KeyEscape) == glfw.Press) {
glfw.setWindowShouldClose(window, true);
}glfw.pollEvents();
}
}
```# Documentation
I would suggest you look into the `glfw.zig` file themselves, as most of the changes are simple syntactically, but I have made some comments in cases where it may be different than you expect. Obviously [GLFW's Documentation](https://www.glfw.org/documentation.html) should cover most things that you want to know.