Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I use the new bindings with SDL.zig? #65

Closed
mstrng opened this issue Nov 30, 2022 · 4 comments
Closed

How do I use the new bindings with SDL.zig? #65

mstrng opened this issue Nov 30, 2022 · 4 comments
Labels
help wanted Extra attention is needed

Comments

@mstrng
Copy link

mstrng commented Nov 30, 2022

I have seen the use of the "gl.load" function, but I don't know how to get the required parameters to pass when using SDL.zig. I have seen the other examples with glfw, but I don't understand or know which parameters have to be passed. My project was working fine before, but now it won't run saying that a function isn't bound.

lib/zgl/binding.zig:2722:54: 0x296d3e in createProgram (usg)
    return (function_pointers.glCreateProgram orelse @panic("glCreateProgram was not bound."))();
                                                     ^
lib/zgl/zgl.zig:757:68: 0x263b9c in createProgram (usg)
    const program = @intToEnum(types.Program, binding.createProgram());
                                                                   ^
src/Renderer.zig:48:38: 0x2636a3 in init (usg)
    const program = gl.Program.create();
    ...
@ikskuh
Copy link
Member

ikskuh commented Nov 30, 2022

In a similar way to the mach-glfw example, you invoke loadExtensions with SDL_GL_GetProcAddress

@mstrng
Copy link
Author

mstrng commented Dec 1, 2022

Well, the following seems to compile and run, but I don't know if it's the intended way to do it:

fn glGetProcAddress(p: []const u8, proc: [:0]const u8) ?*const anyopaque {
    _ = p;
    return sdl.c.SDL_GL_GetProcAddress(@ptrCast([*c]const u8, proc));
}
    const proc: []const u8 = undefined;
    try gl.loadExtensions(proc, glGetProcAddress);

@ikskuh
Copy link
Member

ikskuh commented Dec 1, 2022

you can just use void for the context parameter:

fn glGetProcAddress(_: void, proc: [:0]const u8) ?*const anyopaque {
    return sdl.c.SDL_GL_GetProcAddress(proc.ptr);
}
try gl.loadExtensions({}, glGetProcAddress);

@mstrng mstrng closed this as completed Dec 1, 2022
@ikskuh ikskuh added the help wanted Extra attention is needed label Dec 1, 2022
@jblumie
Copy link

jblumie commented Dec 1, 2022

I think it would be helpful to explain what the function does and maybe document it in the SDL.zig repo?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants