
游戏开发图形学3D渲染【免费下载链接】raylibA simple and easy-to-use library to enjoy videogames programming项目地址https://gitcode.com/GitHub_Trending/ra/raylib点击查看免费下载本文以 raylib 仓库中 examples/README.md 为主体系统讲解官方 222 个示例覆盖 7 大功能分类的构建方法、模块对应关系与示例源码结构。读完本文你将能够用 GNU make 或 Zig 一键编译全部示例、按模块精编单个示例并掌握如何基于 examples_template.c 提交符合官方规范的新示例。构建前置条件先编译 raylib 库本身所有示例都依赖已构建好的raylib库。仓库约定示例源码位于examples/目录库源码位于 src/ 目录因此编译示例前必须先完成 raylib 库本身的构建make或zig build均会自动或按依赖关系处理。示例通过RAYLIB_SRC_PATH ? ../src定位库源码通过INCLUDE_PATHS -I. -I$(RAYLIB_PATH)/src -I$(RAYLIB_PATH)/src/external引入头文件路径见 examples/Makefile。用 GNU make 构建示例在examples/目录下examples/Makefile 提供了三种粒度的构建目标命令作用make构建全部 222 个示例目标all即$(CORE) $(SHAPES) $(TEXT) $(TEXTURES) $(MODELS) $(SHADERS) $(AUDIO)的并集见 Makefilemake [module]构建某一模块下的全部示例例如make core、make shapes、make audiomake [module]/[name]构建单个示例例如make core/core_basic_window平台与关键变量Makefile 通过环境变量控制目标平台与构建行为核心变量如下来源examples/MakefilePLATFORM目标平台默认PLATFORM_DESKTOP桌面默认后端为 GLFW。可选值包括PLATFORM_DESKTOP_GLFWWindows / Linux X11·Wayland / macOS / BSD 系PLATFORM_DESKTOP_SDL需外部提供 SDL 库仓库不内置PLATFORM_DESKTOP_RGFWRGFW 后端PLATFORM_DESKTOP_WIN32原生 Win32PLATFORM_WEB/PLATFORM_WEB_RGFWHTML5 WebAssemblyPLATFORM_DRM树莓派 0-5、Linux DRM/KMSPLATFORM_ANDROIDAndroid ARM/ARM64BUILD_MODERELEASE默认-O2或DEBUG追加-g -D_DEBUG。RAYLIB_LIBTYPESTATIC默认或SHARED。GLFW_LINUX_ENABLE_WAYLAND/GLFW_LINUX_ENABLE_X11Linux 下 GLFW 后端窗口系统开关默认 X11 开启、Wayland 关闭。USE_EXTERNAL_GLFW是否改用系统 GLFW 库默认FALSE使用仓库内置的 rglfw。Web 构建专用变量BUILD_WEB_ASYNCIFY默认TRUE、BUILD_WEB_HEAP_SIZE默认 134217728、BUILD_WEB_SHELL默认src/minshell.html、BUILD_WEB_RESOURCES默认TRUE配合--preload-file打包资源。通用编译标志为-Wall -stdc99 -D_DEFAULT_SOURCE -Wno-missing-braces -Wno-unused-resultRelease 桌面构建追加-O2Web 构建在 Asyncify 开启时用-O3、关闭时用-Os见 Makefile。单条编译规则落在通用模式规则中%: %.c $(CC) -o $$(EXT) $ $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) -D$(TARGET_PLATFORM)注意 Android 与 Web 平台会改走Makefile.Android/Makefile.WebMakefile。清理与常用技巧make clean按平台删除产物桌面删除可执行文件与.oWeb 删除*.wasm/*.html/*.js/*.data。需要单文件快速验证时也可以直接调用 gcc/clang将示例.c、库头文件与libraylib.a组合编译。Windows 桌面 Release 构建默认通过-Wl,--subsystem,windows隐藏控制台窗口并链接raylib.rc.data资源以附带窗口图标。用 Zig 构建示例Zig 工具链除了编译 Zig 代码也能直接编译C/C在交叉编译场景尤其省事。按 examples/README.md 的说明从仓库根目录执行命令作用zig build examples编译全部示例zig build [module]编译某一模块的全部示例例如zig build corezig build [example]编译并运行单个示例例如zig build core_basic_window这一行为由仓库根目录的 build.zig 实现build()中注册了名为examples的步骤并逐个聚合core/audio/models/shaders/shapes/text/textures/others八个子步骤build.zig。addExamples()会动态扫描examples/module/目录下所有.c文件为每个文件生成编译产物与同名的运行步骤zig build core_basic_window会直接启动该示例窗口见 build.zig。Web 目标下zig build examples会借助 zemscripten 将每个示例编译为web/module/name.html并按 examples/example_resources.zon 中声明的src_path - virtual_path映射用--preload-file打包资源例如core_input_gamepad预加载手柄贴图、core_vr_simulator预加载畸变着色器。桌面目标则直接addInstallArtifact安装可执行文件并配置运行工作目录为对应模块目录。示例集合总览222 个示例、7 大分类截至本文撰写示例集合共计222 个分布在 7 个功能分类中。每个分类与 raylib 核心源码模块一一对应是按功能查示例的绝佳索引分类数量对应模块源码覆盖能力core49rcore.c窗口创建、输入、绘制模式与系统功能shapes45rshapes.c2D 图形绘制textures33rtextures.c图片/纹理的加载、生成与绘制text16rtext.c精灵字体加载/生成与文本绘制models32rmodels.c模型加载/生成与绘制shaders36rlgl.h着色器加载、参数配置与绘制模型着色器与后处理着色器audio11raudio.c声音/音乐的加载与播放该模块可脱离 raylib 独立使用说明示例数量以当前仓库 examples/Makefile 中的EXAMPLES_LIST_START/END区块实际列出 222 项与 examples/README.md 的[TOTAL: 222]为准。各分类精选示例详解core49 个窗口、输入与系统功能入门首选 core_basic_window难度 ★☆☆☆一个 800×450 窗口 主循环 DrawText完整展示 raylib 的标准结构初始化 → 主循环 → 反初始化。其余按主题可拆解为输入类core_input_keys、core_input_mouse、core_input_mouse_wheel、core_input_gamepad、core_input_multitouch、core_input_gestures、core_input_actions、core_keyboard_testbed。相机类2D 相机core_2d_camera 等 4 个与 3D 相机core_3d_camera_mode 等 6 个含分屏、FPS、第一人称视角。窗口与显示类core_window_flags、core_window_letterbox、core_window_should_close、core_monitor_detector、core_highdpi_demo、core_viewport_scaling。系统与工具类core_custom_logging、core_drop_files、core_random_values、core_random_sequence、core_storage_values、core_automation_events、core_compute_hash、core_directory_files、core_text_file_loading。渲染进阶类core_render_texture、core_scissor_test、core_smooth_pixelperfect、core_custom_frame_control难度 ★★★★、core_vr_simulator、core_screen_recording。Web 专属core_window_web 演示了 Web 平台下将 Update/Draw 逻辑收敛进UpdateDrawFrame()的写法对应 Makefile.Web 中关于 Asyncify 的说明见 examples/Makefile.Web。shapes45 个2D 图形绘制覆盖 raylib 全部基础 2D 绘制能力shapes_basic_shapes 一网打尽点线圆矩多边形shapes_colors_palette 演示调色板shapes_lines_bezier 与 shapes_splines_drawing 讲解曲线绘制shapes_ring_drawing、shapes_circle_sector_drawing、shapes_rounded_rectangle_drawing 覆盖扇形/环形/圆角矩形shapes_collision_area 演示碰撞检测shapes_easings_* 系列演示缓动动画shapes_rectangle_advanced★★★★、shapes_top_down_lights★★★★、shapes_penrose_tile★★★★则为高难度进阶示例。此外还有 shapes_ball_physics、shapes_hilbert_curve、shapes_recursive_tree 等趣味示例。textures33 个图片与纹理覆盖图片/纹理加载、生成、处理与绘制全链路textures_image_loading、textures_image_generation、textures_image_processing、textures_image_drawing、textures_image_text、textures_image_channel、textures_image_kernel★★★★卷积核处理。绘制与渲染方面有 textures_srcrec_dstrec、textures_sprite_animation、textures_sprite_button、textures_sprite_explosion、textures_bunnymark性能测试、textures_npatch_drawing九宫格、textures_tiled_drawing、textures_blend_modes。进阶示例包括 textures_portal_window★★★★、textures_fog_of_war、textures_framebuffer_rendering、textures_gif_player、textures_screen_buffer、textures_cellular_automata。text16 个字体与文本核心示例包括text_sprite_fonts、text_font_spritefont、text_font_loading、text_font_filters字体过滤、text_font_sdfSDF 字体、text_format_text格式化文本、text_input_box文本输入框、text_writing_anim打字动画。Unicode 与排版类text_unicode_emojis★★★★、text_unicode_ranges★★★★、text_3d_drawing★★★★3D 文本、text_codepoints_loading、text_inline_styling、text_words_alignment、text_strings_management。models32 个3D 模型覆盖模型加载与渲染两大块。加载类models_loadingOBJ、models_loading_gltf、models_loading_iqm、models_loading_m3d、models_loading_vox、models_mesh_generation。渲染类models_geometric_shapes、models_skybox_rendering、models_heightmap_rendering、models_cubicmap_rendering、models_billboard_rendering、models_point_rendering。动画类models_animation_gpu_skinning、models_animation_blending★★★★、models_animation_blend_custom★★★★、models_animation_timing、models_bone_socket★★★★。交互类models_box_collisions、models_mesh_picking、models_first_person_maze、models_yaw_pitch_roll、models_orthographic_projection。高级渲染示例有 models_rlgl_solar_system★★★★、models_decals★★★★、models_procedural_decals★★★★、models_mesh_uv_painting★★★★、models_tesseract_view、models_waving_cubes、models_basic_voxel。shaders36 个着色器与后处理着色器功能由 rlgl.h 直接提供示例分三类模型着色器shaders_model_shader、shaders_basic_lighting★★★★、shaders_basic_pbr★★★★PBR、shaders_cel_shading卡通着色、shaders_normalmap_rendering★★★★法线贴图、shaders_spotlight_rendering、shaders_fog_rendering、shaders_shadowmap_rendering★★★★阴影映射。后处理shaders_postprocessing、shaders_palette_switch、shaders_color_correction、shaders_texture_outline、shaders_multi_sample2d、shaders_depth_rendering、shaders_lights_bloom。GPU 计算与程序化生成shaders_raymarching_rendering★★★★光线步进、shaders_julia_set、shaders_mandelbrot_set、shaders_rlgl_compute★★★★计算着色器、shaders_mesh_instancing★★★★实例化、shaders_deferred_rendering★★★★延迟渲染、shaders_hybrid_rendering★★★★、shaders_game_of_life、shaders_eratosthenes_sieve。实用类还有 shaders_custom_uniform、shaders_hot_reloading着色器热重载、shaders_texture_tiling、shaders_texture_waves、shaders_vertex_displacement、shaders_simple_mask、shaders_rounded_rectangle、shaders_ascii_rendering。audio11 个声音与音乐由 raudio.c 模块提供该模块可以脱离 raylib 独立使用README 中明确说明。核心示例audio_sound_loading、audio_sound_multi多声道、audio_sound_positioning空间音效、audio_music_stream音乐流、audio_module_playing模块播放、audio_raw_stream原始音频流、audio_spectrum_visualizer频谱可视化、audio_stream_callback回调式流处理、audio_stream_effects★★★★流效果、audio_mixed_processor★★★★混音处理器、audio_amp_envelope包络线。示例模板与贡献规范从零提交一个新示例examples/README.md 结尾明确欢迎社区贡献新示例并指向官方模板 examples_template.c。该模板对贡献者提出了一套可量化的规范核心要点如下命名规范module_description小写、下划线分隔、总词数不超过 3-4 个module取代码核心相关的 raylib 模块core/shapes/textures/models/shaders/audio如core_input_multitouch、shapes_lines_bezier。结构规范代码必须按[Initialization] → [Update] → [Draw] → [De-Initialization]四段组织虚线分隔Update 逻辑与绘制逻辑不得混写所有加载的资源必须在退出前卸载。代码规范遵循 raylib 编码约定行内注释克制、客观单个示例尽量控制在300 行以内、尽量不定义main()之外的函数、不引入外部依赖保持自包含。资源规范外部资源放入category/resources/目录且必须为开放、免费、可自由分发的内容禁止专有素材。元数据头每个示例源文件头部需声明模块、复杂度星级、创建/更新版本、贡献者与许可证信息格式见 core_basic_window.c 头部注释。示例集合的数据化管理新示例的接入涉及多个文件的同步更新。仓库为此提供了两个关键支撑examples/examples_list.txt以分号分隔的规范化元数据category;name;stars;created_version;last_update;year_created;year_reviewed;author;github_user是该集合的权威数据源例如core;core_basic_window;★☆☆☆;1.0;1.0;2013;2026;Ramon Santamaria;raysan5。tools/rexmrexmraylib examples manager是官方提供的示例管理流水线工具支持create、add、rename、remove、build、test、validate、update、clean等命令用于自动完成示例新增/改名/删除/校验时对所有关联文件的同步修改Makefile、Makefile.Web、VS2022 工程、README 表格、raylib.com 页面产物等其中validate会生成集合完整性报告。完整的示例接入清单来自 tools/rexm/README.md包括examples/category/name.c、同名.png截图、resources/资源目录、examples/Makefile、examples/Makefile.Web、projects/VS2022/examples 下的.vcxproj、projects/VS2022/raylib.sln、examples/README.md 表格以及 Web 平台的.html/.data/.wasm/.js产物。以模板为骨架的最小示例#include raylib.h int main(void) { // Initialization const int screenWidth 800; const int screenHeight 450; InitWindow(screenWidth, screenHeight, raylib [module] example - name); // TODO: Load resources / Initialize variables at this point SetTargetFPS(60); // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { // Update // TODO: Update variables / Implement example logic at this point // Draw BeginDrawing(); ClearBackground(RAYWHITE); // TODO: Draw everything that requires to be drawn at this point DrawText(example base code template, 260, 400, 20, LIGHTGRAY); EndDrawing(); } // De-Initialization // TODO: Unload all loaded resources at this point CloseWindow(); // Close window and OpenGL context return 0; }这段骨架正是 examples_template.c 的正文也是所有 222 个示例的统一出发点——从InitWindow到while (!WindowShouldClose())主循环再到CloseWindow()构成了 raylib 程序的黄金三角结构。示例源码研读以 core_basic_window 为例最后以仓库中最基础的 core_basic_window.c 为样本串起前面提到的全部构建链路#include raylib.h int main(void) { const int screenWidth 800; const int screenHeight 450; InitWindow(screenWidth, screenHeight, raylib [core] example - basic window); SetTargetFPS(60); while (!WindowShouldClose()) { BeginDrawing(); ClearBackground(RAYWHITE); DrawText(Congrats! You created your first window!, 190, 200, 20, LIGHTGRAY); EndDrawing(); } CloseWindow(); return 0; }桌面构建make core/core_basic_window会执行通用模式规则用 gcc 编译出examples/core/core_basic_window可执行文件。Web 构建make PLATFORMPLATFORM_WEB core/core_basic_window或zig build core_basic_windowemscripten 目标可生成 HTML5 版本注意 Makefile.Web 中提示Web 平台上主循环依赖 Asyncify 才能解释执行阻塞式while()循环更大规模项目应把 Update/Draw 逻辑收敛到UpdateDrawFrame()参考 core_window_web。调试技巧该示例头部注释还提示在编辑器中按 F6 可执行 raylib_compile_execute.bat 一键编译运行编译产物会放在与.c同目录。结语examples/目录是学习 raylib 的最佳入口49 个 core 示例覆盖窗口与输入45 个 shapes 示例覆盖 2D 绘制33 个 textures、16 个 text、32 个 models、36 个 shaders、11 个 audio 示例分别对应 rtextures.c、rtext.c、rmodels.c、rlgl.h、raudio.c 五大核心模块。无论是想照着抄一个弹球游戏还是研究延迟渲染都可以在对应分类中找到难度星级标注★☆☆☆ 到 ★★★★明确、版本历史清晰、贡献者可查的官方参考实现。配合 examples/Makefile、build.zig 与 tools/rexm 工具链你既能一键构建全部示例也能按官方规范向这个集合贡献属于你自己的新示例。赞分享游戏开发图形学3D渲染【免费下载链接】raylibA simple and easy-to-use library to enjoy videogames programming项目地址https://gitcode.com/GitHub_Trending/ra/raylib点击查看免费下载相关推荐TensorLayer 官方 Examples 指南从基础分类到强化学习的完整示例路线图TensorLayer 官方 Examples 指南从基础分类到强化学习的完整示例路线图 本篇指南以 TensorLayer 官方文档 docs/user/e人工智能深度学习机器学习强化学习Solid 官方示例全解析从在线示例到基准测试的学习与实践路线Solid 官方示例全解析从在线示例到基准测试的学习与实践路线 SolidSolidJS是一套声明式、高效且灵活的 JavaScript 用户界面库其核前端终极Shoelace Web组件学习指南从官方Demo到实战应用终极Shoelace Web组件学习指南从官方Demo到实战应用 Shoelace现更名为Web Awesome是一个功能强大的免费Web组件库提供了丰UI组件前端上一篇cube-composer终极指南10个函数式编程益智游戏技巧下一篇Speech-to-Speech开源项目深度解析构建本地语音AI的终极指南创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考