All Projects → Dav1dde → Glad

Dav1dde / Glad

Licence: other
Multi-Language Vulkan/GL/GLES/EGL/GLX/WGL Loader-Generator based on the official specs.

Programming Languages

python
139335 projects - #7 most used programming language
c
50402 projects - #5 most used programming language
pascal
1382 projects
shell
77523 projects
CMake
9771 projects
C++
36643 projects - #6 most used programming language

Projects that are alternatives of or similar to Glad

Glew
The OpenGL Extension Wrangler Library
Stars: ✭ 1,953 (-14.94%)
Mutual labels:  opengl, glx, egl, wgl
Gapid
GAPID is a collection of tools that allows you to inspect, tweak and replay calls from an application to a graphics driver.
Stars: ✭ 1,975 (-13.98%)
Mutual labels:  vulkan, gles, gles2
ux-dx
The core for UX Components and UX Animate
Stars: ✭ 13 (-99.43%)
Mutual labels:  vulkan, egl, gles2
Bgfx
Cross-platform, graphics API agnostic, "Bring Your Own Engine/Framework" style rendering library.
Stars: ✭ 10,252 (+346.52%)
Mutual labels:  opengl, vulkan, gles
Bsf
Modern C++14 library for the development of real-time graphical applications
Stars: ✭ 1,640 (-28.57%)
Mutual labels:  opengl, vulkan
Veldrid
A low-level, portable graphics library for .NET.
Stars: ✭ 1,784 (-22.3%)
Mutual labels:  opengl, vulkan
Gpu Viewer
A front-end to glxinfo, vulkaninfo, clinfo and es2_info - Linux
Stars: ✭ 129 (-94.38%)
Mutual labels:  opengl, vulkan
Diligentsamples
Sample projects demonstrating the usage of Diligent Engine
Stars: ✭ 138 (-93.99%)
Mutual labels:  opengl, vulkan
Xrtl
Cross-platform Real-Time Rendering Library
Stars: ✭ 108 (-95.3%)
Mutual labels:  opengl, vulkan
Filament
Filament is a real-time physically based rendering engine for Android, iOS, Windows, Linux, macOS, and WebGL2
Stars: ✭ 13,215 (+475.57%)
Mutual labels:  opengl, vulkan
Serpent
Cross-platform gaming kit in the D programming language
Stars: ✭ 140 (-93.9%)
Mutual labels:  opengl, vulkan
Duckstation
Fast PlayStation 1 emulator for x86-64/AArch32/AArch64
Stars: ✭ 2,888 (+25.78%)
Mutual labels:  opengl, vulkan
Crossshader
⚔️ A tool for cross compiling shaders. Convert between GLSL, HLSL, Metal Shader Language, or older versions of GLSL.
Stars: ✭ 113 (-95.08%)
Mutual labels:  opengl, vulkan
Gl vk meshlet cadscene
This OpenGL/Vulkan sample illustrates the use of "mesh shaders" for rendering CAD models.
Stars: ✭ 127 (-94.47%)
Mutual labels:  opengl, vulkan
Fna3d
FNA3D - 3D Graphics Library for FNA
Stars: ✭ 111 (-95.17%)
Mutual labels:  opengl, vulkan
Diligentengine
A modern cross-platform low-level graphics library and rendering framework
Stars: ✭ 2,142 (-6.71%)
Mutual labels:  opengl, vulkan
Innocenceengine
Cross-platform modern game engine.
Stars: ✭ 149 (-93.51%)
Mutual labels:  opengl, vulkan
Swiftcolorgen
A tool that generate code for Swift projects, designed to improve the maintainability of UIColors
Stars: ✭ 152 (-93.38%)
Mutual labels:  generator, code-generation
Premulalpha
Pre-Multiplied blend mode is a 3 in 1 blend mode that has a lot of uses. It has been around for a long time but it seems to be re-discovered every few years. This project includes descriptions/examples and tools for using pre-multiplied alpha.
Stars: ✭ 97 (-95.78%)
Mutual labels:  opengl, vulkan
Vkgl
Core OpenGL over Vulkan
Stars: ✭ 105 (-95.43%)
Mutual labels:  opengl, vulkan

glad

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

Use the webservice to generate the files you need!

#include <glad/glad.h>

int main()
{
    // -- snip --

    GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "LearnOpenGL", NULL, NULL);
    glfwMakeContextCurrent(window);

    if (!gladLoadGLLoader((GLADloadproc) glfwGetProcAddress)) {
        std::cout << "Failed to initialize OpenGL context" << std::endl;
        return -1;
    }

    glViewport(0, 0, WIDTH, HEIGHT);

    // -- snip --

The full code: hellowindow2.cpp.

Glad 2

Glad 2 is becoming mature and is pretty stable now, consider using the glad2 branch or its webservice.

There is no need to switch, if you don't want to. I will support both versions.

Glad2 brings several improvements and new features:

  • Better EGL, GLX, WGL support
  • Vulkan Support
  • Rust Support
  • More Generator Features (e.g. header only)
  • Better XML-Specification parsing
  • Better Web-Generator
  • Better Cmake support
  • Better Examples
  • Better CLI
  • Better Loader
  • Better API

If you're using glad for more than GL, I highly recommend checking out glad2.

Usage

If you don't want to install glad you can use the webservice

Otherwise either install glad via pip:

# Windows
pip install glad

# Linux
pip install --user glad
# Linux global (root)
pip install glad

To install the most recent version from Github:

pip install --upgrade git+https://github.com/dav1dde/glad.git#egg=glad

Or launch glad directly (after cloning the repository):

python -m glad --help

Installing and building glad via vcpkg

You can download and install glad using the vcpkg dependency manager:

git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.sh
./vcpkg integrate install
vcpkg install glad

The 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 on the vcpkg repository.

When integrating glad into your build system the --reproducible option is highly recommended.

Generators

C/C++

struct gladGLversionStruct {
    int major;
    int minor;
};

extern struct gladGLversionStruct GLVersion;

typedef void* (* GLADloadproc)(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.
 *
 * Substitute GL with the API you generated
 *
 */
int gladLoadGLLoader(GLADloadproc);

/**
 * WGL and GLX have an unload function to free the module handle.
 * Call the unload function after your last GLX or WGL API call.
 */
void gladUnloadGLX(void);
void gladUnloadWGL(void);

glad.h completely 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_framebuffer_multisample) {
        /* GL_EXT_framebuffer_multisample 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).

Note, there are two kinds of extension/version symbols, e.g. GL_VERSION_3_0 and GLAD_VERSION_3_0. Latter is a runtime boolean (represented as integer), whereas the first (not prefixed with GLAD_) is a compiletime-constant, indicating that this header supports this version (the official headers define these symbols as well). The runtime booleans are only valid after a successful call to gladLoadGL or gladLoadGLLoader.

C/C++ Debug

The C-Debug generator extends the API by these two functions:

// this symbol only exists if generated with the c-debug generator
#define GLAD_DEBUG
typedef void (* GLADcallback)(const char *name, void *funcptr, int len_args, ...);

/*
 * Sets a callback which will be called before every function call
 * to a function loaded by glad.
 *
 */
GLAPI void glad_set_pre_callback(GLADcallback cb);

/*
 * Sets a callback which will be called after every function call
 * to a function loaded by glad.
 *
 */
GLAPI void glad_set_post_callback(GLADcallback cb);

To call a function like glGetError in a callback prefix it with glad_, e.g. the default post callback looks like this:

void _post_call_callback_default(const char *name, void *funcptr, int len_args, ...) {
    GLenum error_code;
    error_code = glad_glGetError();

    if (error_code != GL_NO_ERROR) {
        fprintf(stderr, "ERROR %d in %s\n", error_code, name);
    }
}

You can also submit own implementations for every call made by overwriting the function pointer with the name of the function prefixed by glad_debug_.

E.g. you could disable the callbacks for glClear with glad_debug_glClear = glad_glClear, where glad_glClear is the function pointer loaded by glad.

The glClear macro is defined as #define glClear glad_debug_glClear, glad_debug_glClear is initialized with a default implementation, which calls the two callbacks and the real function, in this case glad_glClear.

FAQ

How do I build glad or how do I integrate glad?

Easiest way of using glad is through the webservice.

Alternatively glad integrates with:

Thanks for all the help and support maintaining those!

glad includes windows.h #42

Since 0.1.30: glad does not include windows.h anymore.

Before 0.1.30: Defining APIENTRY before including glad.h solves this problem:

#ifdef _WIN32
    #define APIENTRY __stdcall
#endif

#include <glad/glad.h>

But make sure you have the correct definition of APIENTRY for platforms which define _WIN32 but don't use __stdcall

What's the license of glad generated code?

#101 #253

The glad generated code itself is any of Public Domain, WTFPL or CC0, the source files for the generated code are under various licenses from Khronos.

Now the Apache License may apply to the generated code (not a lawyer), but see this clarifying comment.

Glad also adds header files form Khronos, these have separated licenses in their header.

Contribute

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

Special thanks for all the people who contributed and are going to contribute! Also to these who helped me solve a problem when I simply could not think of a solution.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].