Binding Generator for OpenGL related Khronos APIs.
Find a file
2026-03-11 13:36:25 +00:00
src always bitcast params and return values except with pointer 2026-03-11 13:35:58 +00:00
.gitignore Add project scaffolding 2026-02-21 08:39:32 +00:00
build.zig Add 'compile' build option to compile generated output 2026-02-24 12:09:13 +00:00
build.zig.zon Update pointer type handling to handle all types that show in the xml 2026-02-24 10:32:50 +00:00
LICENSE Rename copyright to glgn developers 2026-03-11 13:36:25 +00:00
README.md Remove line saying gl.xml is included in repo, it's not. 2026-02-24 12:39:06 +00:00

glgn

Zig binding generator for OpenGL-related Khronos APIs. Parses the Khronos XML registry (gl.xml) and generates type-safe Zig bindings.

Using as a Dependency

Add glgn to your project's build.zig.zon dependencies:

zig fetch --save git+https://git.temporus.me/temporus.zig/glgn.git

Then in your build.zig, consume the dependency and pass it the path to your gl.xml registry file. The generator runs at build time and produces a gl module you can import from your code:

const std = @import("std");

pub fn build(b: *std.Build) void {
    const target = b.standardTargetOptions(.{});
    const optimize = b.standardOptimizeOption(.{});

    const glgn_dep = b.dependency("glgn", .{
        .target = target,
        .optimize = optimize,
        .gl = b.path("gl.xml"), // path to your gl.xml registry file
    });

    const exe = b.addExecutable(.{
        .name = "my-app",
        .root_source_file = b.path("src/main.zig"),
        .target = target,
        .optimize = optimize,
    });

    exe.root_module.addImport("gl", glgn_dep.module("gl"));

    b.installArtifact(exe);
}

Then in your Zig source code:

const gl = @import("gl");

// Load function pointers using your platform's loader (e.g. GLFW):
gl.load(glfw.glfwGetProcAddress);

Obtaining gl.xml

The registry file can be downloaded from the OpenGL-Registry repository:

curl -O https://raw.githubusercontent.com/KhronosGroup/OpenGL-Registry/main/xml/gl.xml

Standalone Usage

Build and run the generator directly:

zig build run -- --api gl gl.xml output.zig

Or generate and install the output as part of the build:

zig build -Dgl=gl.xml

The generated file will be placed at zig-out/src/gl.zig.

To also compile the generated output (useful for verifying it produces valid Zig):

zig build -Dgl=gl.xml -Dcompile=true

License

AGPL-3.0-or-later. See LICENSE for details.