floooh / sokol-zig

Zig bindings for the sokol headers (https://github.com/floooh/sokol)
zlib License
372 stars 49 forks source link

Using OpenGL on macOS #23

Closed tanis2000 closed 2 years ago

tanis2000 commented 2 years ago

Is it just me or it looks like there is no way to force sokol to use OpenGL when compiling for macOS?

floooh commented 2 years ago

Just define SOKOL_GLCORE33 so that it is visible in the implementation (most robust way is to pass this as compiler option, e.g. on gcc/clang -DSOKOL_GLCORE33 or on MSVC /DSOKOL_GLCORE33) that way, if you're using different sokol headers, all will automatically select the same backend.

floooh commented 2 years ago

Ooops wait... we're in sokol-zig here lol, sorry...

Yeah, currently the backend is hardwired to Metal on macOS. You need to fix the backend manually here:

https://github.com/floooh/sokol-zig/blob/master/src/sokol/c/sokol_defines.h

I should probably make this more flexible via build.zig.

floooh commented 2 years ago

Ok, it's now possible to force the GL backend on macOS or Windows like this:

zig build -Dgl=true run-clear

...so far tested on macOS, but will also test on Windows now.

floooh commented 2 years ago

...oops, fails on Windows... fixing...

floooh commented 2 years ago

Ok, Windows and Linux fixed, was a stupid oversight.

tanis2000 commented 2 years ago

I believe you forgot to set the Backend enum to public :)

floooh commented 2 years ago

ah right, one sec

floooh commented 2 years ago

ok fixed: https://github.com/floooh/sokol-zig/commit/73f301e67f84df3a2c114ce48d46196557bab033

tanis2000 commented 2 years ago

awesome! thank you for the quick fix! :)