- Notifications
You must be signed in to change notification settings - Fork32
Zig build package and bindings for GLFW
License
NotificationsYou must be signed in to change notification settings
zig-gamedev/zglfw
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Zig build package and bindings forGLFW 3.4
Examplebuild.zig:
pubfnbuild(b:*std.Build)void {constexe=b.addExecutable(.{... });constzglfw=b.dependency("zglfw", .{});exe.root_module.addImport("zglfw",zglfw.module("root"));if (target.result.os.tag!=.emscripten) {exe.linkLibrary(zglfw.artifact("glfw")); }}
Now in your code you may import and usezglfw:
constglfw=@import("zglfw");pubfnmain()!void {tryglfw.init();deferglfw.terminate();constwindow=tryglfw.createWindow(600,600,"zig-gamedev: minimal_glfw_gl",null);deferglfw.destroyWindow(window);// or, using the equivalent, encapsulated, "objecty" API:constwindow=tryglfw.Window.create(600,600,"zig-gamedev: minimal_glfw_gl",null);deferwindow.destroy();// setup your graphics context herewhile (!window.shouldClose()) {glfw.pollEvents();// render your things herewindow.swapBuffers(); }}
Seezig-gamedev samples for more complete usage examples.
To match types fromzglfw functions and Vulkan libraryimport_vulkan option may be used. When using this optionvulkan import must be provided to the root module.
Examplebuild.zig withvulkan-zig:
constvulkan_headers=b.dependency("vulkan_headers");constvulkan=b.dependency("vulkan_zig", .{ .registry=vulkan_headers.path("registry/vk.xml"),}).module("vulkan-zig");constzglfw=b.dependency("zglfw", .{ .import_vulkan=true });constzglfw_mod=zglfw.module("root");zglfw_mod.addImport("vulkan",vulkan);constexe=b.addExecutable(.{ .name="vk_setup", .root_module=b.createModule(.{ .root_source_file=b.path("src/main.zig"), .target=target, .optimize=optimize, .imports= &.{ .{ .name="zglfw", .module=zglfw_mod }, .{ .name="vulkan", .module=vulkan }, }, }),});exe.root_module.linkLibrary(zglfw.artifact("glfw"));
About
Zig build package and bindings for GLFW
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
No releases published
Packages0
No packages published
Uh oh!
There was an error while loading.Please reload this page.