This is a forked and modified version of glad

The modifications are made for my specific use case in C++. They are ugly. I do not recommend using this fork! It is not even up-to-date.

Original readme is below.


OpenGL/EGL/GLX/WGL Loader-Generator based on the official specs.


  • Always up to date
  • Supports every Extension (GL/EGL/GLX/WGL)
  • Easy to maintain and extend (supporting multiple languages at once)
  • Allows you to use your own loader or e.g. SDL_GL_GetProcAddress instead of the builtin
  • Easy way to check if an extension is loaded if(GL_EXT_Cg_shader) { /* Exists */ }
  • Can generate a loader which fits exactly your needs, only the extensions and version you need

What a D code using glad (and SDL) could look like:

import; // imports all constants and functions, including extensions
import glad.loader : gladLoadGL;
void main() {
    /* setup OpenGL context with SDL */
    enforce(GLVersion.major >= 3 && GLVersion.minor >= 2);
    /* done, use OpenGL here */

Of course you don't need to use SDL, glad provides its own OpenGL loder:

void main() {
    /* setup OpenGL context with e.g. glfw */
    enforce(GLVersion.major == 3 && GLVersion.minor == 2);
    enforce(GL_EXT_texture_filter_anisotropic, "Extension not supported!");
    /* done, use OpenGL here */

You're not familiar with D, here is a C example:

If you don't want to generate your own loader or just wanna check out the generated code:



To generate the loader for your language execute with a Python 2 interpreter.

Possible commandline options:

usage: [-h] [--profile {core,compatibility}] --out-path OUT
            [--api API] [--version VERSION] [--generator {c,d,volt}]
            [--extensions EXTENSIONS] [--spec {gl,egl,glx,wgl}]

Uses the offcial OpenGL spec (gl.xml) to generate an OpenGL loader made for
your needs. glad currently supports the languages C, D and Volt.

optional arguments:
-h, --help              show this help message and exit
--profile {core,compatibility}
                        OpenGL profile (defaults to compatibility)
--out-path OUT          Output path for loader
--api API               API type
--version VERSION       OpenGL version (defaults to latest)
--generator {c,d,volt}
                        Language (defaults to d)
--extensions EXTENSIONS
                        Path to extensions file or comma separated list of
--spec {gl,egl,glx,wgl}
                        Name of spec

By default a loader for the D programming language will be generated. To generate a loader for C with two extensions, it could look like that:

python --generator=c --extensions=GL_EXT_framebuffer_multisample,GL_EXT_Cg_shader --out-path=GL

--out-path is the only required option. If the --extensions option is missing, glad adds support for all extensions found in the OpenGL spec.


The glad loader API follows this convention (if backend generates a loader, this is not the case for Volt but any other language (C and D) have a loader)

struct {
    int major;
    int minor;
} GLVersion;

typedef void* (* LOADER)(const char *name);

 * Load OpenGL using the internal loader.
 * Returns the true/1 if loading succeeded.
int gladLoadGL(void);
 * Load OpenGL using an external loader like SDL_GL_GetProcAddress.
 * Note: in D this function is an overload of gladLoadGL:
 * GLVersion gladLoadGL(void* function(const(char)* name));
void gladLoadGLLoader(LOADER);


glad.h completly replaces any gl.h or gl3.h only include glad.h.

if(!gladLoadGL()) { exit(-1) };
printf("OpenGL Version %d.%d loaded", GLVersion.major, GLVersion.minor);
if(GLAD_GL_EXT_gpu_shader4) { /* GL_EXT_gpu_shader4 is supported */ }
if(GLAD_GL_VERSION_3_0) { /* We support at least OpenGL version 3 */ }

On non-Windows platforms glad requires libdl, make sure to link with it (-ldl for gcc)!


Import for OpenGL functions/extensions, import glad.loader to import the functions needed to initialize glad and load the OpenGL functions.

writefln("OpenGL Version %d.%d loaded", GLVersion.major, GLVersion.minor);
if(GL_EXT_gpu_shader4) { /* GL_EXT_gpu_shader4 is supported */ }
if(GL_VERSION_3_0) { /* We support at least OpenGL version 3 */ }

On non-Windows platforms glad requires libdl, make sure to link with it (L-ldl for dmd)!


Contributing is easy! Found a bug? Message me or make a pull request! Added a new generator backend? Make a pull request!

People contributed sofar (special thanks):