diff --git a/README.en.md b/README.en.md new file mode 100644 index 0000000000000000000000000000000000000000..d08e7b7584ae28ff5c13a27a7164c449f74ae383 --- /dev/null +++ b/README.en.md @@ -0,0 +1,156 @@ +# GLAD + +GLAD (GL Loader-Generator) is a powerful open-source library for generating platform-independent loaders for OpenGL functions. It automatically generates code for loading functions related to various OpenGL versions and extensions. + +## Project Overview + +GLAD is a modern OpenGL loading library that supports all versions from OpenGL 1.0 up to OpenGL 3.3 and beyond. This project enables developers to access OpenGL core features and numerous extensions in a simple manner, without manually writing tedious platform-specific loading code. + +## Key Features + +- **Multi-version Support**: Full support for all versions from OpenGL 1.0 to 3.3 +- **Extension Support**: Supports numerous OpenGL extensions +- **Cross-platform Compatibility**: Works across multiple operating systems +- **Easy Integration**: Simple initialization process—call `gladLoadGL()` to load all functions +- **Type Safety**: Provides complete function pointer type definitions + +## Directory Structure + +``` +. +├── include/ +│ ├── KHR/ +│ │ └── khrplatform.h # Khronos platform header +│ └── glad/ +│ └── glad.h # GLAD main header +└── src/ + └── glad.c # GLAD implementation source file +``` + +## Quick Start + +### Initialization + +Before using GLAD, initialize the OpenGL function loader: + +```c +#include + +int main() { + // Initialize GLAD + if (!gladLoadGL()) { + // Initialization failed + return -1; + } + + // Now OpenGL functions can be used + glClearColor(0.0f, 0.0f, 0.0f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT); + + return 0; +} +``` + +### Using a Custom Loader + +If you need to use a custom function loader: + +```c +#include + +// Custom loader function type +typedef void* (*GLADloadproc)(const char* name); + +// Your loader implementation +void* load_proc(const char* name) { + // Implement platform-specific loading logic + return your_platform_specific_load(name); +} + +int main() { + // Initialize with custom loader + if (!gladLoadGLLoader((GLADloadproc)load_proc)) { + return -1; + } + + // Use OpenGL functions + glClear(GL_COLOR_BUFFER_BIT); + + return 0; +} +``` + +## Version Checking + +GLAD provides version checking functionality: + +```c +#include + +void check_version() { + // Check OpenGL version + int major = GLAD_GL_VERSION_1_0 ? 1 : 0; // Example + + // Or use GLVersion + int major_version = GLVersion.major; + int minor_version = GLVersion.minor; + + // Check for specific version support + if (GLAD_GL_VERSION_2_0) { + // OpenGL 2.0 is supported + } + + if (GLAD_GL_VERSION_3_3) { + // OpenGL 3.3 is supported + } +} +``` + +## Extension Checking + +Check whether a specific extension is available: + +```c +#include + +void check_extension() { + // Check if extension is supported + if (glad_glGetStringi != NULL) { + const char* extensions = (const char*)glGetStringi(GL_EXTENSIONS, 0); + // Use extension + } +} +``` + +## Build Instructions + +### CMake Build + +```bash +mkdir build +cd build +cmake .. +make +``` + +### Direct Inclusion + +Add the `include` directory to your project's include path and compile `src/glad.c`: + +```bash +gcc -I./include -c src/glad.c -o glad.o +``` + +## Dependencies + +- C compiler +- Graphics card and driver supporting OpenGL + +## Related Links + +- Official Documentation: [https://glad.dav1d.de/](https://glad.dav1d.de/) +- Khronos OpenGL Specification: [https://www.opengl.org/](https://www.opengl.org/) + +## License + +This project is open-sourced under the MIT License. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000000000000000000000000000000000000..2153e860712f5dcc9cca401d0a9b16f85a87d3fe --- /dev/null +++ b/README.md @@ -0,0 +1,156 @@ +# Glad + +GLAD (GL Loader-Generator) 是一个功能强大的开源库,用于生成 OpenGL 函数的平台无关加载器。它能够自动生成与 OpenGL 各版本及扩展相关的函数加载代码。 + +## 项目简介 + +GLAD 是一个现代化的 OpenGL 加载库,支持从 OpenGL 1.0 到 OpenGL 3.3 及以上的所有版本。该项目允许开发者以简单的方式访问 OpenGL 的核心功能及各种扩展,无需手动编写繁琐的平台特定加载代码。 + +## 主要特性 + +- **多版本支持**:完整支持 OpenGL 1.0 至 3.3 的所有版本 +- **扩展支持**:支持众多 OpenGL 扩展 +- **跨平台兼容**:可在多种操作系统上使用 +- **易于集成**:简单的初始化流程,调用 `gladLoadGL()` 即可加载所有函数 +- **类型安全**:提供完整的函数指针类型定义 + +## 目录结构 + +``` +. +├── include/ +│ ├── KHR/ +│ │ └── khrplatform.h # Khronos 平台头文件 +│ └── glad/ +│ └── glad.h # GLAD 主头文件 +└── src/ + └── glad.c # GLAD 实现源文件 +``` + +## 快速开始 + +### 初始化 + +在使用 GLAD 之前,需要先初始化 OpenGL 函数加载器: + +```c +#include + +int main() { + // 初始化 GLAD + if (!gladLoadGL()) { + // 初始化失败 + return -1; + } + + // 现在可以使用 OpenGL 函数了 + glClearColor(0.0f, 0.0f, 0.0f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT); + + return 0; +} +``` + +### 使用自定义加载器 + +如果需要使用自定义的函数加载器: + +```c +#include + +// 自定义加载函数类型 +typedef void* (*GLADloadproc)(const char* name); + +// 你的加载器实现 +void* load_proc(const char* name) { + // 实现平台特定的加载逻辑 + return your_platform_specific_load(name); +} + +int main() { + // 使用自定义加载器初始化 + if (!gladLoadGLLoader((GLADloadproc)load_proc)) { + return -1; + } + + // 使用 OpenGL 函数 + glClear(GL_COLOR_BUFFER_BIT); + + return 0; +} +``` + +## 版本检查 + +GLAD 提供了版本检查功能: + +```c +#include + +void check_version() { + // 检查 OpenGL 版本 + int major = GLAD_GL_VERSION_1_0 ? 1 : 0; // 示例 + + // 或者使用 GLVersion + int major_version = GLVersion.major; + int minor_version = GLVersion.minor; + + // 检查特定版本支持 + if (GLAD_GL_VERSION_2_0) { + // 支持 OpenGL 2.0 + } + + if (GLAD_GL_VERSION_3_3) { + // 支持 OpenGL 3.3 + } +} +``` + +## 扩展检查 + +检查特定扩展是否可用: + +```c +#include + +void check_extension() { + // 检查扩展是否支持 + if (glad_glGetStringi != NULL) { + const char* extensions = (const char*)glGetStringi(GL_EXTENSIONS, 0); + // 使用扩展 + } +} +``` + +## 构建说明 + +### CMake 构建 + +```bash +mkdir build +cd build +cmake .. +make +``` + +### 直接包含 + +将 `include` 目录添加到项目的包含路径中,然后编译 `src/glad.c`: + +```bash +gcc -I./include -c src/glad.c -o glad.o +``` + +## 依赖要求 + +- C 编译器 +- 支持 OpenGL 的图形卡和驱动 + +## 相关链接 + +- 官方文档:[https://glad.dav1d.de/](https://glad.dav1d.de/) +- Khronos OpenGL 规范:[https://www.opengl.org/](https://www.opengl.org/) + +## 许可证 + +本项目采用 MIT 许可证开源。 \ No newline at end of file