# Why are all OpenGL function calls prefixed with “q” in the Doom 3 source code?

Why is every OpenGL call prefixed with a "q" in the Doom 3 source code? Are they custom functions or a different library, and if so, why use that over OpenGL? Any Google search comes up with the Qt OpenGL module, which I assume has nothing to do with it.

For reference - Doom3's qgl.h.

OpenGL is an odd little API. You must often work with function pointers either because the standard implementation is missing new functionality or because you want to work with extensions. For instance, if you want to call glCreateShader, but the OS you're developing on doesn't ship with new enough GL headers, you must use glGetProcAddress("CreateShader") in order to load the function out of the user's driver. And then you have to store that function pointer somewhere.

Even if your development environment has a particular function the users' machines might not. And then a certain function can come in 2-3 forms (vendor extension, ARB extension, core function) and so you might have to search for a function under several different names.

Many GL "loader" libraries (like GLEW) try to stick to the GL conventions. They create "fake" functions with the usual gl-prefix and try to magically make your code just work on any OS or driver that supports the necessary features. Essentially, instead of glFoo being an actual function, it's just a global function pointer and the loader library (during initialization or first use) searches FooEXT, FooARB, and Foo until it finds an implementation and then assigns that to the global pointer. The client code looks like it's just calling a regular function but it magically all gets resolved at runtime during initialization in a way that deals with all the different platforms and drivers out there.

Other libraries put the functions in namespaces or otherwise vary a bit from the GL norm. id wrote their own loader, either because they didn't like the ones that existed or - more likely - Quake just predates any other library that id could have used (the q in qgl likely stands for Quake, which was the first id Tech game to use GL).

The GL spec is written with this being a possibility. The spec is written without prefixes; it's the implementation of OpenGL that decides on which prefix to use (gl being the common one, of course). Loader libraries that put the functions in namespaces or using their own prefixes are completely valid.

Doom 3, being based on the Quake engine, is completely typical and justified in using a loader library to deal with the oddities of GL on multiple platforms and in choosing to use the qgl prefix.

• +1, and kudos for spotting I've wrote id bad (you're completely right about the capitalization), though en.wikipedia.org/wiki/Id_Tech is still written with space, in all the sources I could find. – vaxquis Jun 4 '15 at 19:56