glad.c
v1.2025.12
Published
Vulkan/GL/GLES/EGL/GLX/WGL Loader based on the official specs, using glad by David Herberth (2013).
Maintainers
Readme
glad
Vulkan/GL/GLES/EGL/GLX/WGL Loader based on the official specifications for C/C++.
[!NOTE] This repository contains headers generated by glad with the following options:
- Generator: C/C++
- APIs
- egl: Version 1.5
- gl: Version 4.6
- gles1: Version 1
- gles2: Version 3.2
- glsc2: Version 2.0
- glx: Version 1.4
- vulkan: Version 1.4
- vulkansc: Version 1.4 (no loader)
- wgl: 1.0
- Extensions: All
- Options:
- header only: Generate a header only version of glad
- loader: Include internal loaders for APIs
Installation
Run:
$ npm i glad.cAnd then include the needed headers in your source files as follows:
// main.c
#define GLAD_EGL_IMPLEMENTATION
#define GLAD_GL_IMPLEMENTATION
#define GLAD_GLES1_IMPLEMENTATION
#define GLAD_GLES2_IMPLEMENTATION
#define GLAD_GLSC2_IMPLEMENTATION
#define GLAD_GLX_IMPLEMENTATION
#define GLAD_VULKAN_IMPLEMENTATION
#define GLAD_VULKANSC_IMPLEMENTATION
#define GLAD_WGL_IMPLEMENTATION
#include "node_modules/glad.c/glad/egl.h"
#include "node_modules/glad.c/glad/gl.h"
#include "node_modules/glad.c/glad/gles1.h"
#include "node_modules/glad.c/glad/gles2.h"
#include "node_modules/glad.c/glad/glsc2.h"
#include "node_modules/glad.c/glad/glx.h"
#include "node_modules/glad.c/glad/vulkan.h"
#include "node_modules/glad.c/glad/vulkansc.h"
#include "node_modules/glad.c/glad/wgl.h"
int main() { /* ... */ }And then compile with clang or gcc as usual.
$ clang main.c # or, use gcc
$ gcc main.cYou may also use a simpler approach:
// main.c
#define GLAD_EGL_IMPLEMENTATION
#define GLAD_GL_IMPLEMENTATION
#define GLAD_GLES1_IMPLEMENTATION
#define GLAD_GLES2_IMPLEMENTATION
#define GLAD_GLSC2_IMPLEMENTATION
#define GLAD_GLX_IMPLEMENTATION
#define GLAD_VULKAN_IMPLEMENTATION
#define GLAD_VULKANSC_IMPLEMENTATION
#define GLAD_WGL_IMPLEMENTATION
#include <glad/egl.h>
#include <glad/gl.h>
#include <glad/gles1.h>
#include <glad/gles2.h>
#include <glad/glsc2.h>
#include <glad/glx.h>
#include <glad/vulkan.h>
#include <glad/vulkansc.h>
#include <glad/wgl.h>
int main() { /* ... */ }If you add the path node_modules/glad.c to your compiler's include paths.
$ clang -I./node_modules/glad.c main.c # or, use gcc
$ gcc -I./node_modules/glad.c main.cExamples
#include <glad/gl.h>
// GLFW (include after glad)
#include <GLFW/glfw3.h>
int main() {
// -- snip --
GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "LearnOpenGL", NULL, NULL);
glfwMakeContextCurrent(window);
int version = gladLoadGL(glfwGetProcAddress);
if (version == 0) {
printf("Failed to initialize OpenGL context\n");
return -1;
}
// Successfully loaded OpenGL
printf("Loaded OpenGL %d.%d\n", GLAD_VERSION_MAJOR(version), GLAD_VERSION_MINOR(version));
// -- snip --
}The full code: hellowindow2.cpp
More examples in the examples directory of this repository.
Plugins
Glad plugins maintained by the community to add support for more languages:
Documentation
The documentation can be found in the wiki.
Examples can be found in the example directory. Some examples:
- C/C++
- Rust
License
The generated code from glad is in WTFPL. Now Khronos has some of their specifications under Apache Version 2.0 license which may have an impact on the generated code, see this clarifying comment on the Khronos / OpenGL-Specification issue tracker.
