OpenGL on Linux: dlopen libGL.so OpenGL on Linux: dlopen libGL.so linux linux

OpenGL on Linux: dlopen libGL.so


There are two main reasons people do this:

  1. You can give a sensible error for systems that don't have OpenGL
  2. Vendors offer many different extensions and the only sane way to support multiple sets of extensions without different binaries per vendor is to use dlsym to check for them. GLEW offers a nice way of doing this for you though.


This is made so you don't have to statically link to a GL implementation, for example, if your code uses glBindFragDataLocation, which is available on OpenGL 3.0 and newer, it would fail to run with a cryptic linker error on OpenGL 2.1 and earlier implementations.

So getting entry points dynamically allows you to select the apropiate rendering path at runtime.

Also, it's required on Windows for GL functions > 1.1.

GLEW does this for you, it doesn't dlopen libGL, it uses glXGetProcAddress/wglGetProcAddress/aglGetProcAddress to get GL function pointers from the driver, and it's cross platform.