• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

example/H07-Sep-2020-356224

glad/H07-Sep-2020-65,22862,656

utility/H07-Sep-2020-308217

.gitignoreH A D07-Sep-2020160 1918

Config.cmake.inH A D07-Sep-2020113 53

LICENSEH A D07-Sep-20202.9 KiB6446

MANIFEST.inH A D07-Sep-202048 21

README.mdH A D07-Sep-20209.5 KiB301211

setup.pyH A D07-Sep-20202.3 KiB7159

README.md

1glad
2====
3
4GL/GLES/EGL/GLX/WGL Loader-Generator based on the official specs.
5
6Use the [webservice](https://glad.dav1d.de) to generate the files you need!
7
8
9```c
10#include <glad/glad.h>
11
12int main(int argc, char **argv)
13{
14    // .. setup the context
15
16    if(!gladLoadGL()) {
17        printf("Something went wrong!\n");
18        exit(-1);
19    }
20    printf("OpenGL %d.%d\n", GLVersion.major, GLVersion.minor);
21
22    // .. render here ..
23}
24```
25
26Examples:
27 * [simple.c](https://github.com/Dav1dde/glad/blob/master/example/c/simple.c)
28 * [hellowindow2.cpp](https://github.com/Dav1dde/glad/blob/master/example/c%2B%2B/hellowindow2.cpp)
29 using [GLFW](https://glfw.org):
30
31
32## Usage ##
33
34
35**If you don't want to install glad you can use the [webservice](https://glad.dav1d.de)**
36
37
38Otherwise either install glad via pip:
39
40    # Windows
41    pip install glad
42
43    # Linux
44    pip install --user glad
45    # Linux global (root)
46    pip install glad
47
48    glad --help
49
50To install the most recent version from Github:
51
52    pip install --upgrade git+https://github.com/dav1dde/glad.git#egg=glad
53
54Or launch glad directly (after cloning the repository):
55
56    python -m glad --help
57
58Installing and building glad via vcpkg
59
60You can download and install glad using the [vcpkg](https://github.com/Microsoft/vcpkg) dependency manager:
61
62    ```
63    git clone https://github.com/Microsoft/vcpkg.git
64    cd vcpkg
65    ./bootstrap-vcpkg.sh
66    ./vcpkg integrate install
67    vcpkg install glad
68    ```
69
70The glad port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please [create an issue or pull request](https://github.com/Microsoft/vcpkg) on the vcpkg repository.
71
72
73Possible commandline options:
74
75    usage: glad [-h] [--profile {core,compatibility}] --out-path OUT
76                     [--api API] --generator {c,d,volt}
77                     [--extensions EXTENSIONS] [--spec {gl,egl,glx,wgl}]
78                     [--no-loader]
79
80    Uses the official Khronos-XML specs to generate a GL/GLES/EGL/GLX/WGL Loader
81    made for your needs. Glad currently supports the languages C, D and Volt.
82
83    optional arguments:
84      -h, --help            show this help message and exit
85      --profile {core,compatibility}
86                            OpenGL profile (defaults to compatibility)
87      --out-path OUT        Output path for loader
88      --api API             API type/version pairs, like "gl=3.2,gles=", no
89                            version means latest
90      --generator {c,c-debug,d,volt}
91                            Language to generate the binding for
92      --extensions EXTENSIONS
93                            Path to extensions file or comma separated list of
94                            extensions, if missing all extensions are included
95      --spec {gl,egl,glx,wgl}
96                            Name of the spec
97      --reproducible        Makes the build reproducible by not fetching
98                            the latest specification from Khronos
99      --no-loader
100      --omit-khrplatform    Omits inclusion of the khrplatform.h file which is
101                            often unnecessary. Only has an effect if used
102                            together with c generators.
103      --local-files         Forces every file directly into the output directory.
104                            No src or include subdirectories are generated. Only
105                            has an effect if used together with c generators.
106
107
108To generate a loader for C with two extensions, it could look like this:
109
110    python main.py --generator=c --extensions=GL_EXT_framebuffer_multisample,GL_EXT_texture_filter_anisotropic --out-path=GL
111
112`--out-path` and `--generator` are required!
113If the `--extensions` option is missing, glad adds support for all extensions found in the specification.
114
115When integrating glad into your build system the `--reproducible` option is highly recommended,
116it prevents the build from failing in case Khronos made incompatible changes to the specification.
117
118
119## Generators ##
120
121### C/C++ ###
122
123```c
124struct gladGLversionStruct {
125    int major;
126    int minor;
127};
128
129extern struct gladGLversionStruct GLVersion;
130
131typedef void* (* GLADloadproc)(const char *name);
132
133/*
134 * Load OpenGL using the internal loader.
135 * Returns the true/1 if loading succeeded.
136 *
137 */
138int gladLoadGL(void);
139
140/*
141 * Load OpenGL using an external loader like SDL_GL_GetProcAddress.
142 *
143 * Substitute GL with the API you generated
144 *
145 */
146int gladLoadGLLoader(GLADloadproc);
147```
148
149`glad.h` completely replaces any `gl.h` or `gl3.h` only include `glad.h`.
150
151```c
152    if(!gladLoadGL()) { exit(-1); }
153    printf("OpenGL Version %d.%d loaded", GLVersion.major, GLVersion.minor);
154
155    if(GLAD_GL_EXT_framebuffer_multisample) {
156        /* GL_EXT_framebuffer_multisample is supported */
157    }
158
159    if(GLAD_GL_VERSION_3_0) {
160        /* We support at least OpenGL version 3 */
161    }
162```
163
164On non-Windows platforms glad requires `libdl`, make sure to link with it (`-ldl` for gcc)!
165
166Note, there are two kinds of extension/version symbols, e.g. `GL_VERSION_3_0` and
167`GLAD_VERSION_3_0`. Latter is a runtime boolean (represented as integer), whereas
168the first (not prefixed with `GLAD_`) is a compiletime-constant, indicating that this
169header supports this version (the official headers define these symbols as well).
170The runtime booleans are only valid *after* a succesful call to `gladLoadGL` or `gladLoadGLLoader`.
171
172
173### C/C++ Debug ###
174
175The C-Debug generator extends the API by these two functions:
176
177```c
178// this symbol only exists if generated with the c-debug generator
179#define GLAD_DEBUG
180typedef void (* GLADcallback)(const char *name, void *funcptr, int len_args, ...);
181
182/*
183 * Sets a callback which will be called before every function call
184 * to a function loaded by glad.
185 *
186 */
187GLAPI void glad_set_pre_callback(GLADcallback cb);
188
189/*
190 * Sets a callback which will be called after every function call
191 * to a function loaded by glad.
192 *
193 */
194GLAPI void glad_set_post_callback(GLADcallback cb);
195```
196
197To call a function like `glGetError` in a callback prefix it with `glad_`, e.g.
198the default post callback looks like this:
199
200```c
201void _post_call_callback_default(const char *name, void *funcptr, int len_args, ...) {
202    GLenum error_code;
203    error_code = glad_glGetError();
204
205    if (error_code != GL_NO_ERROR) {
206        fprintf(stderr, "ERROR %d in %s\n", error_code, name);
207    }
208}
209```
210
211You can also submit own implementations for every call made by overwriting
212the function pointer with the name of the function prefixed by `glad_debug_`.
213
214E.g. you could disable the callbacks for glClear with `glad_debug_glClear = glad_glClear`, where
215`glad_glClear` is the function pointer loaded by glad.
216
217The `glClear` macro is defined as `#define glClear glad_debug_glClear`,
218`glad_debug_glClear` is initialized with a default implementation, which calls
219the two callbacks and the real function, in this case `glad_glClear`.
220
221
222### D ###
223
224Import `glad.gl` for OpenGL functions/extensions, import `glad.loader` to import
225the functions needed to initialize glad and load the OpenGL functions.
226
227```d
228    enforce(gladLoadGL()); // optionally you can pass a loader to this function
229    writefln("OpenGL Version %d.%d loaded", GLVersion.major, GLVersion.minor);
230
231    if(GL_EXT_framebuffer_multisample) {
232        /* GL_EXT_framebuffer_multisample is supported */
233    }
234
235    if(GL_VERSION_3_0) {
236        /* We support at least OpenGL version 3 */
237    }
238```
239
240On non-Windows platforms glad requires `libdl`, make sure to link with it (`L-ldl` for dmd)!
241
242
243## FAQ ##
244
245### How do I build glad or how do I integrate glad?
246
247Easiest way of using glad is through the [webservice](https://glad.dav1d.de).
248
249Alternatively glad integrates with:
250
251* `CMake`
252* [Conan](https://bintray.com/bincrafters/public-conan/glad%3Abincrafters)
253[![Download](https://api.bintray.com/packages/bincrafters/public-conan/glad%3Abincrafters/images/download.svg) ](https://bintray.com/bincrafters/public-conan/glad%3Abincrafters/_latestVersion)
254
255Thanks for all the help and support maintaining those!
256
257### glad includes windows.h [#42](https://github.com/Dav1dde/glad/issues/42)
258
259**Since 0.1.30:** glad does not include `windows.h` anymore.
260
261**Before 0.1.30:**
262Defining `APIENTRY` before including `glad.h` solves this problem:
263
264```c
265#ifdef _WIN32
266    #define APIENTRY __stdcall
267#endif
268
269#include <glad/glad.h>
270```
271
272But make sure you have the correct definition of `APIENTRY` for platforms which define `_WIN32` but don't use `__stdcall`
273
274### What's the license of glad generated code?
275[#101](https://github.com/Dav1dde/glad/issues/101)
276[#253](https://github.com/Dav1dde/glad/issues/253)
277
278The glad generated code itself is any of Public Domain, WTFPL or CC0,
279the source files for the generated code are under various licenses
280from Khronos.
281
282* EGL: See [egl.xml](https://github.com/KhronosGroup/EGL-Registry/blob/master/api/egl.xml#L4)
283* GL: Apache Version 2.0
284* GLX: Apache Version 2.0
285* WGL: Apache Version 2.0
286* Vulkan: Apache Version 2.0 [with exceptions for generated code](https://raw.githubusercontent.com/KhronosGroup/Vulkan-Docs/master/xml/vk.xml)
287
288Now the Apache License may apply to the generated code (not a lawyer),
289but see [this clarifying comment](https://github.com/KhronosGroup/OpenGL-Registry/issues/376#issuecomment-596187053).
290
291Glad also adds header files form Khronos,
292these have separated licenses in their header.
293
294## Contribute ##
295
296Contributing is easy! Found a bug? Message me or make a pull request! Added a new generator backend?
297Make a pull request!
298
299Special thanks for all the people who contributed and are going to contribute!
300Also to these who helped me solve a problem when I simply could not think of a solution.
301