Home > front end >  Why is linking to opengl32.dll required?
Why is linking to opengl32.dll required?

Time:01-26

In order to use modern OpenGL functions above legacy version 1.1, a loading library is required (unless you manually load the function pointers from the GPU drivers yourself of course). If opengl32.dll only contains a software legacy OpenGL 1.1 implementation for windows, why is it still required to be linked to by loading libraries like GLEW or internally loaded by GLAD?

CodePudding user response:

As alluded to in the comments above, openGL32.dll contains the method wglGetProcAddress. This is pretty much the only function that you need for openGL.

The loader libraries (e.g. glew, glad, et al) are basically a load of function pointers. Those function pointers need to be initialised at startup, hence needing to call glewInit, which will actually just make a load of calls to wglGetProcAddress.

Basically glew will essentially boil down to something along these lines internally:

// declare a function pointer type
typedef void (*glFlushPointer)();

// a global function pointer
glFlushPointer glFlush = 0;

#include <GL/gl.h> //< required for wglGetProcAddress

void glewInit() {
    // now repeat this process for every GL function you need...
    glFlush = (glFlushPointer)wglGetProcAddress("glFlush");
}
  • Related