当前位置: 首页 > news >正文

0384-Raylib-混合模式

环境

  • Time 2024-02-29
  • Zig 0.12.0-dev.3076+6e078883e
  • WSL-Ubuntu 22.04.3 LTS
  • Raylib 5.0

前言

说明

参考资料:

  1. https://www.raylib.com/examples.html

目标

实现不同的混合模式。

main.zig

const std = @import("std");
const ray = @import("raylib.zig");pub fn main() !void {const screenWidth: c_int = 800;const screenHeight: c_int = 450;ray.InitWindow(screenWidth, screenHeight, "raylib [shapes] example");defer ray.CloseWindow();ray.SetTargetFPS(60);const background = ray.LoadTexture("res/cyberpunk_street_background.png");defer ray.UnloadTexture(background);const foreground = ray.LoadTexture("res/cyberpunk_street_foreground.png");defer ray.UnloadTexture(foreground);const blendCountMax = 4;var blendMode: ray.BlendMode = 0;while (!ray.WindowShouldClose()) {// Updateif (ray.IsKeyPressed(ray.KEY_SPACE)) {if (blendMode >= (blendCountMax - 1)) blendMode = 0 else blendMode += 1;}// Drawray.BeginDrawing();defer ray.EndDrawing();ray.ClearBackground(ray.RAYWHITE);var x = @divTrunc(screenWidth, 2) - @divTrunc(background.width, 2);var y = @divTrunc(screenHeight, 2) - @divTrunc(background.height, 2);ray.DrawTexture(background, x, y, ray.WHITE);// Apply the blend mode and then draw the foreground textureray.BeginBlendMode(@intCast(blendMode));x = @divTrunc(screenWidth, 2) - @divTrunc(foreground.width, 2);y = @divTrunc(screenHeight, 2) - @divTrunc(foreground.height, 2);ray.DrawTexture(foreground, x, y, ray.WHITE);ray.EndBlendMode();// Draw the textsray.DrawText("Press SPACE to change blend modes.", 310, 350, 10, ray.GRAY);switch (blendMode) {ray.BLEND_ALPHA => ray.DrawText("Current: BLEND_ALPHA", (screenWidth / 2) - 60, 370, 10, ray.GRAY),ray.BLEND_ADDITIVE => ray.DrawText("Current: BLEND_ADDITIVE", (screenWidth / 2) - 60, 370, 10, ray.GRAY),ray.BLEND_MULTIPLIED => ray.DrawText("Current: BLEND_MULTIPLIED", (screenWidth / 2) - 60, 370, 10, ray.GRAY),ray.BLEND_ADD_COLORS => ray.DrawText("Current: BLEND_ADD_COLORS", (screenWidth / 2) - 60, 370, 10, ray.GRAY),else => {},}const text = "(c) Cyberpunk Street Environment by Luis Zuno (@ansimuz)";ray.DrawText(text, screenWidth - 330, screenHeight - 20, 10, ray.GRAY);ray.DrawFPS(screenWidth - 100, 10);}
}

图片:https://github.com/raysan5/raylib/blob/master/examples/textures/resources/

效果

混合模式

总结

实现不同的混合模式。

附录

http://www.jsqmd.com/news/1360281/

相关文章:

  • 同一股票池两端顺序不同:QMT、PTrade用稳定排序复现结果
  • 广州装修公司口碑**真实推荐 - 品牌品鉴馆
  • 暗黑破坏神2存档编辑器终极指南:5分钟快速修改角色装备属性
  • 2026 年采购钢格栅为什么推荐丹姐《振邦源头厂家》 - 优企甄选
  • 5个目标管理模型,把想法变成现实
  • 如何永久解锁Wand专业版:5分钟解决2小时限制的完整指南
  • 国产大模型实战指南:Qwen、DeepSeek、GLM选型与集成开发
  • Vue+Spring Boot构建高效在线书城系统实践
  • 2026年河北实验室蠕动泵厂家盘点:齐力产品优势及选购要点汇总 - 董不懂啊
  • 2026东莞装修高口碑推荐丨从施工到售后,轩怡家装如何提升东莞业主装修体验? - 天下观知
  • 树形DP解决括号匹配问题:CSP-S2019括号树题解
  • PL-2303驱动终极解决方案:让老旧工业设备在Windows 10系统重获新生
  • 2026培根选购避坑指南|从配料表到烹饪效果,实测教你选对好培根 - 产品评测官
  • CSS content-visibility:提升页面渲染性能的现代技术
  • 【ComfyUI】MiniMax-H3 极速版集成包,解压即用:6步采样+SageAttention加速+8G显存低配流畅运行教程
  • 厨卫管道堵塞不用愁!2026上海本地马桶、地漏、洗菜池疏通实用联系方式 - 品牌商讯
  • 2026年企业即时通讯与移动门户平台怎么选?5款产品按场景对比 - IM软件测评
  • 2026番禺区废旧金属回收靠谱服务商口碑参考:四家对比与合规避坑指南 - 互联网科技品牌测评
  • BERT模型原理与应用:从预训练到微调实战指南
  • 2026年上海市闵行区装修如何选择?——怎么选择更可靠|**选购指南 - 盟道科技
  • 如何通过NVIDIA Profile Inspector实现游戏性能精准调校:从入门到精通的完整指南
  • 2026售后服务系统发展趋势:AI智能服务成为企业核心竞争力
  • 常见算法题型之构造基础:数字构造
  • 深入理解库调用:原理、实践与优化技巧
  • 2026疏通电话推荐,地漏疏通,疏通地漏,洗菜池疏通,疏通马桶电话优选指南! - 品牌商讯
  • 湖北就要学高考学校介绍 - 湖北就要学教育
  • C++策略模式进阶:现代实现与工程实践
  • 2026宿州成人专科/高起专怎么报名?推荐宿州航空学院! - 最新资讯
  • AirPlay 2协议在Windows平台的技术实现与实践
  • 2026年周口工程窗帘优质品牌推荐,全维度实力解析! - 品牌品鉴馆