Gaffer Docs

Win32 OpenGL - The Easy Way

Years ago, Microsoft implemented OpenGL 1.0 and 1.1 and you can still call those functions quite simply just by including gl.h and linking to opengl32.lib.

Of course, we want to be able to call more modern functions of the standard, but how do we do it? You could use a third party solution, like GLEW, but I tend to shy away from additional external dependencies unless they save time or testing.

It turns out, the solution is suprisingly simple.

Microsoft provides an api, called wglGetProcAddress, to retrieve a function pointer from the graphics driver for a named OpenGL function. If the graphics driver doesn't support it, it returns NULL.

A call to a function pointer is syntactically identical to a call to a function that exists in an included header file. If we can somehow build all of these function pointers and include them correctly, our code can call any OpenGL function it wants just as if they were all provided through the traditional header/lib method.

All you need to do is grab gl3.h from, write a script to parse it, which creates a .cpp file that has global function pointer variables (named exactly the same as their corresponding OpenGL functions), and a header file that declares all of these variables as externs.

Gaffer does exactly this, and the resulting files are gagl.h and gagl.cpp. I wrote a simple Python script that takes gl3.h as input and generates these files.

This is an almost painless solution, and doesn't create an unecessary external dependency just to call OpenGL functions in Windows.

If anyone is interested in the details or wants a copy of the Python script, drop me a line. My email is at the bottom of this page.