Home

OpenGL Loader Generator

This loader generation system is used to create OpenGL headers and loading code for your specific needs. Rather than getting every extension and core enumerator/function all in one massive header, you get only what you actually want and ask for. This tool supports OpenGL 4.4 and the recent crop of OpenGL extensions.

Download it here; you will need to have the Lua runtime installed on your machine to use the code generation scripts. It's pretty tiny, so it shouldn't be a problem. Windows users can install Lua For Windows, or just the Lua binaries packages. The code should be compatible with Lua 5.1 and 5.2, but it has only been tested on 5.1.

Note: this script is designed to be stand-alone. There is a caveat: Lua lacks any real filesystem commands, so the script cannot create directories for the destination files. However, if you have installed the Lua FileSystem Lua module (such that Lua can detect it), then this script will access and use it to create directories. It comes with Lua For Windows, but you can use LuaRocks to install it on any platform as well.

The scripts in this package are licensed under the terms of the MIT License.

Basic Usage

To use the code generator, with Lua in your path (assuming that lua is the name of your Lua executable), type this:

lua LoadGen.lua -style=pointer_c -spec=gl -version=3.3 -profile=core core_3_3

This tells the system to generate a header/source pair for OpenGL (-spec=gl, as opposed to WGL or GLX), for version 3.3, the core profile. It will generate it in the pointer_c style, which means that it will use function pointer-style, with C linkage and source. Such code is usable from C and C++, or other languages that can interface with C.

The option core_3_3 is the basic component of the filename that will be used for the generation. Since it is generating OpenGL loaders (again, as opposed to WGL or GLX), it will generate files named gl_core_3_3.*, where * is the extension used by the particular style.

The above command line will generate gl_core_3_3.h and gl_core_3_3.c files. Simply include them in your project; there is no library to build, no unresolved externals to filter through.

You will need to call ogl_LoadFunctions to initialize the library if you use the pointer_c style. And you must call it after OpenGL context creation. For example, if you are using FreeGLUT, your code looks like this:

//Pre-window creation.
int windowID = glutCreateWindow("Name");

if(ogl_LoadFunctions() == ogl_LOAD_FAILED)
{
  glutDestroyWindow(windowID);
}
//Call functions here.

Replace the "Pre-window creation" and glutCreateWindow call with your usual OpenGL context creation code.

The full command-line syntax documentation is available. Of particular note is the -style parameter, which defines how the loader is generated. Different styles will have different initialization needs and so forth (you don't even need to initialize some styles at all). The available styles are:

  • pointer_c: Function-pointer-based style for C. It is the most widely compatible, comparable to GLEW. It has variables to test whether an extension was loaded (and how many of its functions were loaded). Like GLEW, it requires calling an initialization function to set it up. This is best used for C or C++ users who need to be able to share the headers with other tools (note: usually, you don't need to do this).
  • pointer_cpp: Function-pointer-based style for C++. It wraps all function pointers, extension variables, and enumerators in a namespace (not the typedefs). It requires calling an initialization function to set it up. This is best used for C++ users who don't need compatibility, but would like OpenGL stuff to not pollute the global namespace so much.
  • func_cpp: Inline-function-based style for C++. This means that the header contains actual inline functions, which forward their parameters to the actual function pointers internally. Like pointer_cpp, most of OpenGL is in a namespace. This is best used for C++ users who want the best possible autocompletion from their IDE or coding tool of choice.
  • noload_c: Automatic loading style for C. This is similar to the old loading tool GLee. Unlike the other styles, it does not require an initialization function; you simply call whatever function you want to use. The first time a call is encountered, it will load that function. This is best used for C or C++ users who don't want to do explicit initialization, and also want header compatibility like pointer_c.
  • noload_cpp: Automatic loading style for C++. This is similar to the old loading tool GLee. Unlike the other styles, it does not require an initialization function; you simply call whatever function you want to use. The first time a call is encountered, it will load that function. It will wrap most of OpenGL in a namespace. This is best used for C++ users who don't want to do explicit initialization.

Each linked page has instructions on how to use the generated interface.

More about styles can be found on the style page.

Extensions

Note that the above command line will only generate enumerators and functions for core OpenGL 3.3. It doesn't offer any extensions. To use extensions, you must ask for them with command line parameters, as follows:

lua LoadGen.lua -style=pointer_c -spec=gl -version=3.3 -profile=core core_3_3 -exts ARB_texture_view ARB_vertex_attrib_binding EXT_texture_filter_anisotropic -ext=EXT_texture_compression_s3tc -extfile=SomeFile.txt

The -exts option starts a list of space-separated extension names (note: don't try to put the output filename after -exts; the system can't tell the difference between a filename and an extension). The -ext option only specifies a single name.

-extfile specifies a filename to load extensions from. The format of this file is fairly simple; it is explained here on this site. The file is expected to contain extension names, one on each line. Extension files can also have #include directives, which will include another extension file (relative pathing only). Please don't infinitely recurse your inclusions; there's no protection in the system to check for it.

The system has a number of common extension files that store useful sets of extensions. You may use these as you wish.

Examples

Here are some example command lines. This command-line generates loaders for core OpenGL 3.3, without proprietary extensions, but with non-hardware features that were added to OpenGL in later versions:

lua LoadGen.lua core_3_3 -style=pointer_c -spec=gl -version=3.3 -profile=core -stdext=gl_ubiquitous.txt -stdext=gl_core_post_3_3.txt

This command-line is for OpenGL 4.4, but with certain commonly-provided extensions that are generally useful.

lua LoadGen.lua core_4_4 -style=pointer_c -spec=gl -version=4.4 -profile=core -stdext=gl_ubiquitous.txt -stdext=gl_plat_3_3.txt

This command-line generates a header that exposes OpenGL 3.2 for what MacOSX 10.8 uses (note: the loader generator files have not been tested with MacOSX of any kind):

lua LoadGen.lua core_3_2 -style=pointer_c -spec=gl -version=3.2 -profile=core -stdext=gl_ubiquitous.txt -stdext=gl_macosx_3_2.txt

Updated

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.