zgl icon indicating copy to clipboard operation
zgl copied to clipboard

Instructions of usage and setup

Open Flecart opened this issue 1 year ago • 2 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).

Flecart avatar Sep 16 '23 13:09 Flecart

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.

KnockerPulsar avatar Oct 24 '23 22:10 KnockerPulsar

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

Flecart avatar Oct 25 '23 14:10 Flecart