Clone wiki

glLoadGen / Style_No_Load_CPP

The noload_cpp style works a lot like the near-defunct GLee loader. You don't need to call a function to load all of the function pointers; instead, you simply call the GL functions as normal. If it hasn't been loaded, it will be. This makes it among the most user-friendly of the loader styles.

As a C++ style, it follows the naming conventions of the pointer_cpp style. Everything is scoped into namespaces. The enumerators don't have the GL_ prefix on them, and so forth.

The system is designed to be automatic, responding to your application's needs. However, calling a function that the implementation does not provide will result in a crash, just as it would for the previous system.

To help alleviate this, the system does have variables to tell you which extensions are available (at least, according to the extension strings). They are located in the exts namespace, using the var_<extension name> syntax, and they are C++ bool types. However, unlike the magic function pointers, you have to actually initialize them. You can call sys::CheckExtensions to initialize them. This function only initializes the extension variables, so it cannot report on the number of functions that failed to load.


This example is for loading the OpenGL functions; it expects the OpenGL header to be included. For loading WGL/GLX functions, include their headers and change the "gl" namespaces to "wgl" or "glx" as appropriate.

//Create OpenGL context and make it current.

That was a trick question: there is no initialization required. That is the whole point of this style, after all.

However, if you want to query which extensions are around, you need to initialize that:

//Create OpenGL context and make it current.

The presence of extensions can be checked as follows:

  gl::CompressedTexSubImage2D(gl::TEXTURE_2D, 0, 0, 0, 256, 256,
    gl::COMPRESSED_RGBA_S3TC_DXT5_EXT, compressedSize, compressedPixels);
  void *decompressedPixels = DecompressPixels(256, 256,
    compressedSize, compressedPixels);

  gl::TexSubImage2D(gl::TEXTURE_2D, 0, 0, 0, 256, 256,
    gl::RGBA, gl::UNSIGNED_BYTE, decompressedPixels);


When you use this system and provide a version number of OpenGL, noload_cpp will assume that you are serious about that version number. Which means that if you create a 3.3 header, and you do not supply a context that claims support for at least OpenGL version 3.3, crashing may occur.

In particular, OpenGL changed the mechanism to check for the presence/absence of extensions in version 3.0. Therefore, noload_cpp will also change how it checks for the presence/absence of extensions based on that. If you provide a version 3.0 or greater, it will use the new style. Thus, if your context is only version 2.1, then this style will be unable to function and will likely crash when it fails to load an appropriate function pointer.