Metric Panda Games

One pixel at a time.

OpenGL Minimal Loader

Rival Fortress Update #6

If you’ve ever worked with OpenGL you know that extension loading is always a bit of a pain.

You can either do it manually, by loading the correct library for your platform and getting function pointers for the OpenGL functions you need, or you can use one of the many extension loaders, like GLEW, GL3W.

Since with Rival Fortress I’m trying to minimize dependencies for a number of reasons, I decided to roll my own extension loader.

glgen

glgen is a command line tool that generates an header file with a minimal extension loader. The loader only loads OpenGL functions that are actually made in the project.

The generator works by parsing project files and generating typedefs, #defines and function pointers using definitions that are extracted from header files provided by the Khronos OpenGL API registry.

The biggest advantage over traditional OpenGL extension loaders is a faster startup time for your application, as well as a better view on what OpenGL functions you are actually using.

The tool is currently very simple and naive, as it only looks for tokens that start with gl or GL_ but I’ll probably add better token parsing as the need arises. In its current form it is perfect for rapid development.

glgen with CMake

The tool is part of my CMakeLists.txt and it is run on every build since all my OpenGL calls are made from a couple of files, so builds are still blazing fast.

Take a look at the Readme on the project file for more information about glgen.