Question

If I just use glcorearb.h, can I link against OpenGL functions that aren't provided in the 1.1 OpenGL.lib that comes with MSVC? When I just include the header (with GL_GLEXT_PROTOTYPES defined) and compile, I get a bunch of unresolved externals, and when I

#define GLAPI __declspec(dllimport)

I get a bunch of __imp__ unresolved externals. Where do these symbols come from anyway? Dependency Walker doesn't give me anything useful here.

If I can do this, how do I set it up in MSVC?

I ask because I don't need any of the advanced functionality that the loaders provide, (ie support detection) but I do need modern OpenGL.

Was it helpful?

Solution

No, you need a "loader" (either GLEW or GLee, or something you write/generate your own). It won't otherwise work.

The presence of GL_GLEXT_PROTOTYPES does suggest that you can simply "link against something" so it just works, but that isn't the case, do not define it (honestly, I have no idea what it exists for at all).
Having to resolve symbols at runtime is both a blessing and a curse with OpenGL, but you're not going to get around it. The best thing is not to waste your time thinking about it and simply download GLEW. It works and you get your program done.
If GLEW is too bloated or not pretty enough, you can use one of the available "loader generators" which generate a specific subset of version plus extensions from the specification, I think Alfonse Reinhart has one at Github.

If you only need 5-6 functions, you may consider loading them by hand too ("write your own loader"), but writing a fully fledged loader (or a loader generator) yourself is a huge waste of time and not at all trivial to do correctly (I've done that in the past, so I know).

OTHER TIPS

You can use wglGetProcAddress() to resolve symbols:

glprofile.h:

#define APIENTRY __stdcall

extern GLuint (APIENTRY *glCreateShader_ptr)(GLenum);
#define glCreateShader glCreateShader_ptr
...

glprofile.c:

GLunint (APIENTRY *glCreateShader_ptr)(GLenum) = 0;
...

// Should be called after GL context creation
void initGl() {
    glCreateShader_ptr = (GLuint (APIENTRY *)(GLenum))wglGetProcAddress("glCreateShader");
    ...
}

That's what GLEW actually does.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top