Skip to content

Latest commit

 

History

History

zglfw

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

zglfw v0.9.0 - Zig build package and bindings for GLFW 3.4

Getting started

Copy zglfw and system-sdk to a subdirectory of your project and add the following to your build.zig.zon .dependencies:

    .zglfw = .{ .path = "libs/zglfw" },
    
    // Required for building glfw
    .system_sdk = .{ .path = "libs/system-sdk" },

Then in your build.zig add:

pub fn build(b: *std.Build) void {
    const exe = b.addExecutable(.{ ... });

    const zglfw = b.dependency("zglfw", .{});
    exe.root_module.addImport("zglfw", zglfw.module("root"));
    exe.linkLibrary(zglfw.artifact("glfw"));

    @import("system_sdk").addLibraryPathsTo(exe);
}

Now in your code you may import and use zglfw:

const glfw = @import("zglfw");

pub fn main() !void {
    try glfw.init();
    defer glfw.terminate();

    const window = try glfw.Window.create(600, 600, "zig-gamedev: minimal_glfw_gl", null);
    defer window.destroy();

    // setup your graphics context here

    while (!window.shouldClose()) {
        glfw.pollEvents();

        // render your things here
        
        window.swapBuffers();
    }
}

See zig-gamedev samples for more complete usage examples.