Convert Figma logo to code with AI

Dav1dde logoglad

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

3,722
440
3,722
15

Top Related Projects

2,461

Dead Simple OpenGL

12,827

A multi-platform library for OpenGL, OpenGL ES, Vulkan, window and input

60,541

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies

22,183

A simple and easy-to-use library to enjoy videogames programming

Quick Overview

GLAD (GL/GLES/EGL/GLX/WGL Loader-Generator) is a multi-language GL/GLES/EGL/GLX/WGL loader-generator. It generates a loader based on the official specifications for multiple languages including C, D, Nim, Pascal, and Rust. GLAD simplifies the process of loading OpenGL functions and extensions for developers.

Pros

  • Supports multiple languages (C, D, Nim, Pascal, Rust)
  • Generates loaders based on official specifications
  • Customizable to include only needed extensions and versions
  • Easy to use with a web-based generator interface

Cons

  • Requires regeneration when new OpenGL versions or extensions are released
  • May have a slight performance overhead compared to manually loading functions
  • Documentation could be more comprehensive for some languages
  • Limited to OpenGL-related APIs (doesn't cover other graphics APIs like Vulkan)

Code Examples

  1. Initializing GLAD in C:
#include <glad/glad.h>
#include <GLFW/glfw3.h>

// ... (GLFW window creation code)

if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
{
    printf("Failed to initialize GLAD\n");
    return -1;
}
  1. Checking for an extension in C:
if (GLAD_GL_EXT_texture_filter_anisotropic)
{
    // Use anisotropic filtering
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 4.0f);
}
  1. Using a core OpenGL 4.5 function in C:
GLuint vao;
glCreateVertexArrays(1, &vao);
glBindVertexArray(vao);

Getting Started

  1. Visit the GLAD web service: https://glad.dav1d.de/
  2. Select the language, specification, and API version
  3. Choose the extensions you need
  4. Generate the loader files
  5. Download and include the generated files in your project
  6. For C, add the following to your code:
#include <glad/glad.h>

// In your initialization function:
if (!gladLoadGL())
{
    // Handle initialization failure
}
  1. Compile your project, linking against the appropriate libraries for your platform

Competitor Comparisons

2,461

Dead Simple OpenGL

Pros of Glitter

  • Provides a complete project template for OpenGL, including CMake setup and basic structure
  • Includes additional libraries like GLFW and GLM, offering a more comprehensive starting point
  • Easier to get started with a full OpenGL project, especially for beginners

Cons of Glitter

  • Less flexible and customizable compared to Glad's focused approach
  • Potentially includes unnecessary components for some projects
  • May require more setup time if you only need specific OpenGL loader functionality

Code Comparison

Glad (loader generation):

glad_gl_load(load_proc);

Glitter (project setup):

add_subdirectory(glitter)
target_link_libraries(${PROJECT_NAME} glitter)

Summary

Glad is a focused OpenGL loader generator, while Glitter is a more comprehensive OpenGL project template. Glad offers flexibility and customization for loading OpenGL functions, whereas Glitter provides a complete project structure with additional libraries. The choice between them depends on project requirements and developer preferences.

12,827

A multi-platform library for OpenGL, OpenGL ES, Vulkan, window and input

Pros of GLFW

  • Provides a complete windowing and input system for OpenGL applications
  • Cross-platform support for Windows, macOS, and Linux
  • Actively maintained with regular updates and improvements

Cons of GLFW

  • Larger scope and potentially more complex to integrate than GLAD
  • May include unnecessary features for projects only needing OpenGL loading

Code Comparison

GLFW (window creation):

#include <GLFW/glfw3.h>

int main() {
    glfwInit();
    GLFWwindow* window = glfwCreateWindow(800, 600, "GLFW Window", NULL, NULL);
    glfwMakeContextCurrent(window);
}

GLAD (OpenGL function loading):

#include <glad/glad.h>

int main() {
    // ... (window creation code)
    gladLoadGL();
    // OpenGL functions can now be called
}

Summary

GLFW is a comprehensive library for creating windows with OpenGL contexts and handling input, while GLAD focuses solely on loading OpenGL functions. GLFW is ideal for complete application development, whereas GLAD is more suitable for projects that only need OpenGL function loading and prefer to handle windowing separately.

60,541

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies

Pros of ImGui

  • Provides a complete GUI system for immediate mode rendering
  • Highly customizable and easy to integrate into existing projects
  • Extensive documentation and examples available

Cons of ImGui

  • Larger codebase and potentially higher memory footprint
  • May require more setup and configuration for basic usage

Code Comparison

ImGui example:

ImGui::Begin("Hello, world!");
ImGui::Text("This is some useful text.");
if (ImGui::Button("Save"))
    MySaveFunction();
ImGui::End();

GLAD example:

gladLoadGL();
printf("OpenGL %s", glGetString(GL_VERSION));
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);

Key Differences

  • ImGui focuses on GUI creation, while GLAD is an OpenGL loader
  • ImGui is primarily C++ based, whereas GLAD supports multiple languages
  • GLAD is more lightweight and specific to OpenGL functionality

Use Cases

  • ImGui: Creating debug interfaces, tools, and in-game menus
  • GLAD: Loading OpenGL functions for graphics applications and games

Community and Support

Both projects have active communities, but ImGui tends to have more frequent updates and a larger user base due to its broader application in game development and tools.

22,183

A simple and easy-to-use library to enjoy videogames programming

Pros of raylib

  • Comprehensive game development framework with built-in graphics, audio, and input handling
  • Cross-platform support for desktop, web, and mobile platforms
  • Extensive documentation and examples for easy learning

Cons of raylib

  • Larger project scope and codebase, potentially more complex for simple OpenGL tasks
  • Less flexibility for low-level OpenGL operations compared to GLAD

Code Comparison

raylib:

#include "raylib.h"

int main() {
    InitWindow(800, 450, "raylib example");
    while (!WindowShouldClose()) {
        BeginDrawing();
        ClearBackground(RAYWHITE);
        DrawText("Hello, raylib!", 190, 200, 20, LIGHTGRAY);
        EndDrawing();
    }
    CloseWindow();
    return 0;
}

GLAD:

#include <glad/glad.h>
#include <GLFW/glfw3.h>

int main() {
    glfwInit();
    GLFWwindow* window = glfwCreateWindow(800, 600, "GLAD example", NULL, NULL);
    glfwMakeContextCurrent(window);
    gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
    while (!glfwWindowShouldClose(window)) {
        glClear(GL_COLOR_BUFFER_BIT);
        glfwSwapBuffers(window);
        glfwPollEvents();
    }
    glfwTerminate();
    return 0;
}

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

glad

Vulkan/GL/GLES/EGL/GLX/WGL Loader-Generator based on the official specifications for multiple languages.

Check out the webservice for glad2 to generate the files you need!

NOTE: This is the 2.0 branch, which adds more functionality but changes the API.

Some languages are only available in the glad1 generator.

Examples

#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.

Documentation

The documentation can be found in the wiki.

Examples can be found in the example directory. Some examples:

License

For the source code and various Khronos files see LICENSE.

The generated code from glad is any of Public Domain, WTFPL or CC0. 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.