joshua-software-dev/zgl
Zig OpenGL Wrapper
This library provides a thin, type-safe binding for OpenGL.
// Use classic OpenGL flavour
var vao = gl.createVertexArray();
defer gl.deleteVertexArray(vao);
// Use object oriented flavour
var vertex_buffer = gl.Buffer.create();
defer vertex_buffer.delete();
Add zgl to your build.zig.zon with the following command:
zig fetch --save 'git+https://codeberg.org/joshua-software-dev/zgl.git#[commit_hash]'
Replace [commit_hash] with the latest commit or tagged release.
Then add the following to your build.zig:
const zgl = b.dependency("zgl", .{
.target = target,
.optimize = optimize,
.binding_version = @as([]const u8, "GL_VERSION_4_6"),
});
exe.root_module.addImport("zgl", zgl.module("zgl"));
Then import it with const gl = @import("zgl");, and build as normal with zig build.
This library is developed incrementally. That means that functions and other things will be included on-demand and not just for the sake of completeness.
If you think a function is missing, fork the library, implement the missing function similar to the other functions and make a pull request. Issues that request implementation of missing functions will be closed immediately.
This library includes bindings for OpenGL 1.0 through 4.6, as well as OpenGL ES 1.0 through 3.2, generated by zig-opengl. Alternate bindings can be selected in your build.zig file:
const zgl_dep = b.dependency("zgl", .{
.target = target,
.optimize = optimize,
.binding_version = @as([]const u8, "VERSION_4_1"),
});
You can specify any OpenGL binding version from the following list:
GL_VERSION_1_0GL_VERSION_1_1GL_VERSION_1_2GL_VERSION_1_3GL_VERSION_1_4GL_VERSION_1_5GL_VERSION_2_0GL_VERSION_2_1GL_VERSION_3_0GL_VERSION_3_1GL_VERSION_3_2GL_VERSION_3_3GL_VERSION_4_0GL_VERSION_4_1GL_VERSION_4_2GL_VERSION_4_3GL_VERSION_4_4GL_VERSION_4_5GL_VERSION_4_6GL_ES_VERSION_1_0GL_ES_VERSION_2_0GL_ES_VERSION_3_0GL_ES_VERSION_3_1GL_ES_VERSION_3_2