floooh / sokol

minimal cross-platform standalone C headers
https://floooh.github.io/sokol-html5
zlib License
6.53k stars 467 forks source link

Help using sokol_app with OpenGL on Windows #1047

Closed GoldenbergDaniel closed 1 month ago

GoldenbergDaniel commented 1 month ago

I'm not sure how to get OpenGL working with sokol_app on Windows. On macOS, all I need to do is include the GL header file provided by Apple and link against the OpenGL framework. But since windows only provides OpenGL 1.1 support, I assume I have to use a loader (to get them from the GPU driver). My idea is to use GLAD, but I can't find any function that returns the loader for gladLoadGLLoader to use. Any help would be much appreciated.

GoldenbergDaniel commented 1 month ago

I found that OpenGL loading was moved out of sokol_app, so just calling gladLoadGL worked well for me.

floooh commented 1 month ago

An external GL loader or GL headers are not needed on Windows both for sokol_app.h and sokol_gfx.h since both headers are coming with their own GL loaders which are enabled by default (but can be disabled).

What types of problems were you seeing?

PS: sokol_app.h itself only calls the glGetIntegerv() function, the rest are WGL functions. Those are initialized here:

https://github.com/floooh/sokol/blob/f70cc07f0fcd763ab6ff0171a6b8fe1dca3ed367/sokol_app.h#L6628-L6669

...and the Windows GL loader in sokol_gfx.h is implemented here for the definitions:

https://github.com/floooh/sokol/blob/f70cc07f0fcd763ab6ff0171a6b8fe1dca3ed367/sokol_gfx.h#L4523-L4772

...and the rest is here:

https://github.com/floooh/sokol/blob/f70cc07f0fcd763ab6ff0171a6b8fe1dca3ed367/sokol_gfx.h#L6803-L6956

floooh commented 1 month ago

...ah I think I understand. You are probably using sokol_app.h with your own GL function calls (instead of sokol_gfx.h), and expect that sokol_app.h loads the GL headers for you. Yep, that's indeed not the case on Windows (since the Windows SDK doesn't have uptodate GL headers). You'll have to use a GL loader.

Here's an example where I'm doing somthing similar (call directly into GL functions). In that case I use flextGL as GL loader (and disable sokol_gfx.h's GL loader):

https://github.com/floooh/sokol-samples/blob/master/glfw/multiwindow-glfw.c