Bit of a mouthful. This loads OpenGL symbols in Zig on macOS so you can pass it to gl.load(...)
.
Use it with https://github.com/MasterQ32/zig-opengl and a windowing system of your choice (e.g. GTK).
Loosely adapted from Apple Docs: https://developer.apple.com/library/archive/documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/opengl_entrypts/opengl_entrypts.html#//apple_ref/doc/uid/TP40001987-CH402-SW6
License: Whatever you want (CC-0/Public Domain/Unlicense/etc)
const dyld = @cImport(@cInclude("mach-o/dyld.h"));
pub fn myNsglGetProcAddress(_: void, name: [:0]const u8) ?gl.FunctionPointer {
const symbolName = std.fmt.allocPrintZ(std.heap.page_allocator, "_{s}", .{name}) catch unreachable;
if (dyld.NSIsSymbolNameDefined(symbolName)) {
const symbol = dyld.NSLookupAndBindSymbol(symbolName);
const address = dyld.NSAddressOfSymbol(symbol);
return @alignCast(address);
}
@panic("no findy :(");
}
fn setup_gl_area(gl_area: *gtk.GLArea) void {
gl_area.makeCurrent();
if (gl_area.getError() != null) {
std.log.err("Failed to make GLArea current", .{});
return;
}
// Load OpenGL
std.debug.print("Epoxy Version: {any}", .{epoxy.epoxy_gl_version()});
gl.load({}, myNsglGetProcAddress) catch unreachable;
gl_area.queueRender();
}