Binding Generator for OpenGL related Khronos APIs.
- Zig 100%
| src | ||
| .gitignore | ||
| build.zig | ||
| build.zig.zon | ||
| LICENSE | ||
| README.md | ||
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.