ziglibs / zgl

Zig OpenGL Wrapper

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Instructions of usage and setup

Flecart opened this issue · comments

currently this repo is not clear nor informative on how to include and use it.

Things that I think should be specified:

  1. How to link openGL with the bindings?
  2. further usage examples

For example on point 1, I'm getting segment fault because probably the function pointers are undefined (point to 0).

I agree that at least a basic example should be included to help new users since there isn't a ton of projects out there using zgl yet. I managed to brute-force my way to a bit of working code in a few hours. I'm using SDL but the code should be similar with whatever libarary you're using, it just needs a GetProcAddress counterpart:

pub const c = @cImport({
    @cInclude("SDL2/SDL.h");
});

const zgl = @import("zgl");

fn getProcAddressWrapper(comptime _: type, symbolName: [:0]const u8) ?*const anyopaque {
    return c.SDL_GL_GetProcAddress(symbolName);
}

fn init_opengl() {
  // Init SDL

  try zgl.loadExtensions(void, getProcAddressWrapper);
  
  // Use zgl with zig bindings or C-API bindings
}

This isn't the same exact code I use in my application, but it should get you going with zgl. Feel free to reply if something is not working correctly.

Hi @KnockerPulsar, at the end I was able to make it work using mach-glfw, you can see an example here: https://github.com/Flecart/zig-learnopengl/blob/main/src/chapter-1/1.2.zig#L41