I know manually loading GL functions is usually a bad idea but I am making a 64kB demo (exe cannot go beyond this size limit) so using GLEW does not seem to be an option. It is enough to get this working on Windows.
In VS 2015 I link with opengl32.lib and then I use a helper function like this:
void *GetAnyGLFuncAddress(const char *name)
{
void *p = (void *)wglGetProcAddress(name);
if (p == 0 || (p == (void*)0x1) || (p == (void*)0x2) || (p == (void*)0x3) || (p == (void*)-1))
{
HMODULE module = LoadLibraryA("opengl32.dll");
p = (void *)GetProcAddress(module, name);
}
return p;
}
An example usage:
// GL functions header, definitions copied from https://www.opengl.org/registry/api/GL/glext.h
#define GLAPIENTRY __stdcall
typedef void (GLAPIENTRY *PFGLCLEAR)(GLuint mask);
typedef GLuint(GLAPIENTRY * PFNGLCREATEPROGRAMPROC) (void);
// program
PFGLCLEAR glClear = (PFGLCLEAR) GetAnyGLFuncAddress("glClear");
PFNGLCREATEPROGRAMPROC glCreateProgram = (PFNGLCREATEPROGRAMPROC)GetAnyGLFuncAddress("glCreateProgram");
This approach worked for glClear and glClearColor but getting any other function pointers after that failed (glCreateProgram, glCreateShader...). Why doesn't it work, and why does it work for those first two? Thanks.