# Raylib

**Raylib** 是一个免费开源的 C 语言编程库，用于电子游戏与多媒体编程，以简单易用为设计目标；它提供窗口创建、2D 与 3D 图形、输入处理、文本和音频等函数，所有必需的外部库都内嵌在源码树中。<sup>[1](https://github.com/raysan5/raylib/blob/master/README.md?plain=1)</sup><sup> • </sup><sup>[2](https://github.com/raysan5/raylib/blob/master/FAQ.md)</sup> 它由拉蒙·桑塔马里亚（raysan5）创建，自 2013 年起由他维护，采用未修改的 zlib/libpng 许可证——一种经 OSI 认证、类似 BSD 的许可证，允许与闭源软件进行静态链接。<sup>[3](https://github.com/raysan5/raylib/blob/master/examples/core/core_basic_window.c)</sup><sup> • </sup><sup>[1](https://github.com/raysan5/raylib/blob/master/README.md?plain=1)</sup>

| 关键事实 | 详情 |
|---|---|
| 是什么 | 一个用于游戏编程的 C99 图形与多媒体库，以纯 C 编写，采用 PascalCase/camelCase 命名<sup>[1](https://github.com/raysan5/raylib/blob/master/README.md?plain=1)</sup> |
| 许可证 | 未修改的 zlib/libpng，允许与闭源软件静态链接<sup>[1](https://github.com/raysan5/raylib/blob/master/README.md?plain=1)</sup> |
| 图形后端 | OpenGL 1.1、2.1、3.3、4.3、ES 2.0、ES 3.0，以及无需 GPU 的 rlsw 软件渲染器<sup>[1](https://github.com/raysan5/raylib/blob/master/README.md?plain=1)</sup> |
| 平台 | Windows、Linux（桌面与原生 DRM）、macOS、FreeBSD/OpenBSD/NetBSD/DragonFly、树莓派、Android、HTML5（WebAssembly）、Haiku<sup>[2](https://github.com/raysan5/raylib/blob/master/FAQ.md)</sup> |
| 当前版本 | raylib 6.0，2026 年 4 月 23 日发布，约 600 个 API 函数<sup>[4](https://github.com/raysan5/raylib/blob/master/CHANGELOG)</sup> |
| 学习资料 | 官方示例集约 215 个代码示例，另有一份列出全部函数的速查表<sup>[5](https://github.com/raysan5/raylib/blob/master/examples/README.md?plain=1)</sup><sup> • </sup><sup>[1](https://github.com/raysan5/raylib/blob/master/README.md?plain=1)</sup> |
| 语言绑定 | 支持 70 多种编程语言的绑定<sup>[1](https://github.com/raysan5/raylib/blob/master/README.md?plain=1)</sup> |

## 历史与版本

Raylib 的版权声明将项目起始年份标为 2013 年，作者把 Borland 的 BGI 图形库和微软的 XNA 框架列为它的灵感来源。<sup>[3](https://github.com/raysan5/raylib/blob/master/examples/core/core_basic_window.c)</sup><sup> • </sup><sup>[1](https://github.com/raysan5/raylib/blob/master/README.md?plain=1)</sup>

**5.0 的平台拆分。** 5.0 版重构了 `rcore` 模块，桑塔马里亚称这可能是近十年来 raylib 规模最大的一次重新设计。最初该库通过 GLFW 库面向三个桌面平台，但对 Android、Web 和[树莓派](https://www.edgepedia.org/zh/raspberry-pi)的支持逐渐堆积在同一个文件里，靠编译标志加以区分。

**Raylib 6.0。** 6.0 版于 2026 年 4 月 23 日发布，部分资金来自 NLnet 和 NGI Zero Commond 基金；作者称这是有史以来最大的一个版本：自上一版本以来超过 2000 次提交，约 330 个已关闭的问题，新增 20 个 API 函数、总数约 600 个，新增 70 个示例、总数约 215 个，新增 210 位贡献者、总数约 850 位。<sup>[4](https://github.com/raysan5/raylib/blob/master/CHANGELOG)</sup> 其最大亮点是 `rlsw`，一个让 raylib 完全在 CPU 上运行、无需 GPU 的软件渲染器。它由勒·朱埃兹·维克托（Bigfoot71）创建，是 OpenGL 1.1+ 规范的单文件、仅头文件实现，嵌入 raylib 的 `rlgl` 封装层，因此现有代码无需改动即可运行；软件渲染比硬件加速慢，但对基础应用而言足够快，可达 30 至 60 fps。<sup>[6](https://raysan5.itch.io/raylib/devlog/1497342/raylib-60-released)</sup> 6.0 版还新增了实验性的 Win32 和 [Emscripten](https://www.edgepedia.org/zh/emscripten) 平台后端、一个渲染到与平台无关的帧缓冲以供无头使用的 Memory 后端、重新设计的全屏与高 DPI 缩放、重新设计的[骨骼动画](https://www.edgepedia.org/zh/skeletal-animation)系统，以及新的文件系统与文本管理 API。<sup>[4](https://github.com/raysan5/raylib/blob/master/CHANGELOG)</sup>

## 架构与模块

raylib 由一小组自包含的模块构成，而非层层嵌套的依赖树。七个主模块共用一个公共头文件 `raylib.h`，用户只需包含一个文件即可访问整个 API：<sup>[7](https://github-wiki-see.page/m/raysan5/raylib/wiki/raylib-architecture)</sup>

- `rcore`：窗口、图形上下文与输入管理
- `rlgl`：OpenGL 封装层与伪 OpenGL 1.1 转换层
- `rshapes`：基础 2D 图形绘制
- `rtextures`：纹理与图像的加载和管理
- `rtext`：字体加载与文本绘制
- `rmodels`：3D 模型的加载与绘制
- `raudio`：音频设备管理以及声音与音乐播放

只有 `rcore` 和 `rlgl` 是必需的，其余模块由 `src/config.h` 中的 `SUPPORT_MODULE_*` 标志控制。<sup>[8](https://deepwiki.com/raysan5/raylib/2-core-architecture)</sup> 另有一组附加模块，涵盖向量、矩阵与四元数数学（`raymath`）、3D 相机（`rcamera`）、触摸手势（`rgestures`）、面向工具的即时模式 GUI（`raygui`）、资源打包（`rres`）以及软件渲染器（`rlsw`）。其中大多数以可配置的单文件、仅头文件库的形式分发，可以脱离 raylib 本身单独使用。<sup>[7](https://github-wiki-see.page/m/raysan5/raylib/wiki/raylib-architecture)</sup>

外部依赖内嵌在 `src/external` 目录中，这也是该项目宣称没有外部依赖的原因；其中包括 肖恩·巴雷特用于图像和字体的 stb 库、[大卫·里德](https://www.edgepedia.org/zh/david-reid)的 miniaudio 用于音频设备管理，以及 多米尼克·沙布列夫斯基的 QOI 图像支持。<sup>[1](https://github.com/raysan5/raylib/blob/master/README.md?plain=1)</sup><sup> • </sup><sup>[9](https://github.com/raysan5/raylib/blob/master/src/raylib.h)</sup>

一个基础程序即可展现该库的形态：`InitWindow()` 打开窗口，`while (!WindowShouldClose())` 循环在 `BeginDrawing()` 与 `EndDrawing()` 之间逐帧运行，最后由 `CloseWindow()` 关闭。<sup>[1](https://github.com/raysan5/raylib/blob/master/README.md?plain=1)</sup>

## 特性与限制

raylib 支持 TTF、OTF、FNT、BDF 和精灵字体；包括 DXT、ETC 和 ASTC 在内的压缩纹理格式；带模型、公告板和高度图的完整 3D；带 PBR 贴图的材质系统；IQM、M3D 和 glTF 格式的骨骼动画；包括后处理在内的自定义 GLSL 着色器；可配置头戴显示器参数的 VR 立体渲染；以及 WAV、QOA、OGG、MP3、FLAC、XM 和 MOD 格式的音频加载与流式播放。<sup>[1](https://github.com/raysan5/raylib/blob/master/README.md?plain=1)</sup>

若干限制是为代码简洁而刻意做出的设计选择，README 中坦率列出：默认单窗口、单个 OpenGL 上下文，不支持多窗口；在窗口化平台上，窗口缩放与移动会中止渲染循环；渲染纹理按 OpenGL 提供的方式垂直翻转，用户必须自行翻转绘制；字体光栅化质量低于使用 FreeType2、HarfBuzz 或 Slug 的替代方案；文本绘制不支持从右到左的文字、连字或表情符号。<sup>[1](https://github.com/raysan5/raylib/blob/master/README.md?plain=1)</sup>

## 学习方式与生态

raylib 有意让人通过示例而非参考文档来学习。项目不提供标准的 API 文档，而是提供一份列出全部函数并附简短说明的速查表，以及一个按模块分类的大型示例集，每个示例都附有难度估计。<sup>[1](https://github.com/raysan5/raylib/blob/master/README.md?plain=1)</sup><sup> • </sup><sup>[2](https://github.com/raysan5/raylib/blob/master/FAQ.md)</sup> 官方声明的主要学习方法是“通过阅读代码和示例来学习”，源码也为此目的写有大量注释。<sup>[10](https://github.com/raysan5/raylib/blob/master/CONTRIBUTING.md)</sup>

围绕该库的生态包括面向众多 IDE 的现成项目模板、一个跨平台快速上手模板、一个官方游戏模板仓库，以及 70 多种语言的绑定，从 C++ 和 C# 到 Rust、Ada 和 x86 汇编。<sup>[1](https://github.com/raysan5/raylib/blob/master/README.md?plain=1)</sup><sup> • </sup><sup>[11](https://github.com/raylib-extras/raylib-quickstart)</sup><sup> • </sup><sup>[12](https://github.com/raysan5/raylib/blob/master/BINDINGS.md)</sup> 软件渲染器还把 raylib 带到了微控制器上：一个 ESP-IDF 组件让它在不支持 GPU 的 ESP32 板子上运行，在 320x240 分辨率下可达约 15 至 20 fps。<sup>[13](https://components.espressif.com/components/georgik/raylib)</sup>

## 定位：是库，不是引擎

桑塔马里亚在项目 FAQ 中的回答是：raylib 是一个带有若干高层特性的图形库，而不是游戏引擎。它提供了简单游戏和小型应用所需的东西，但不包含他认为引擎应具备的三要素：屏幕管理器、GameObject 或 Entity 管理器，以及资源管理器。<sup>[2](https://github.com/raysan5/raylib/blob/master/FAQ.md)</sup> FAQ 指出，中小型 2D 游戏最适合使用它，不过只要投入足够的时间和精力，任何类型的应用都能构建，包括桌面与网页工具，以及面向树莓派等物联网设备的应用。<sup>[2](https://github.com/raysan5/raylib/blob/master/FAQ.md)</sup>

## References

1. [raylib README, raysan5/raylib GitHub repository](https://github.com/raysan5/raylib/blob/master/README.md?plain=1)
2. [raylib FAQ.md, raysan5/raylib GitHub repository](https://github.com/raysan5/raylib/blob/master/FAQ.md)
3. [core_basic_window.c example, raysan5/raylib GitHub repository](https://github.com/raysan5/raylib/blob/master/examples/core/core_basic_window.c)
4. [raylib CHANGELOG, raysan5/raylib GitHub repository](https://github.com/raysan5/raylib/blob/master/CHANGELOG)
5. [raylib examples README, raysan5/raylib GitHub repository](https://github.com/raysan5/raylib/blob/master/examples/README.md?plain=1)
6. [raylib 6.0 release notes, raysan5 on itch.io](https://raysan5.itch.io/raylib/devlog/1497342/raylib-60-released)
7. [raylib architecture, raylib GitHub Wiki](https://github-wiki-see.page/m/raysan5/raylib/wiki/raylib-architecture)
8. [Core Architecture, DeepWiki raysan5/raylib](https://deepwiki.com/raysan5/raylib/2-core-architecture)
9. [raylib.h, raysan5/raylib GitHub repository](https://github.com/raysan5/raylib/blob/master/src/raylib.h)
10. [raylib CONTRIBUTING.md, raysan5/raylib GitHub repository](https://github.com/raysan5/raylib/blob/master/CONTRIBUTING.md)
11. [raylib-quickstart, raylib-extras on GitHub](https://github.com/raylib-extras/raylib-quickstart)
12. [raylib BINDINGS.md, raysan5/raylib GitHub repository](https://github.com/raysan5/raylib/blob/master/BINDINGS.md)
13. [Raylib for ESP-IDF, ESP Component Registry](https://components.espressif.com/components/georgik/raylib)

---
*Initially written Sep 17, 2026 · Reviewed: Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 软件与编程 › Development tools and collaboration infrastructure › Frameworks, libraries, and APIs › Graphics and multimedia APIs

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/raylib

English original: https://www.edgepedia.org/raylib
