26 个版本
0.1.26 | 2021 年 5 月 14 日 |
---|---|
0.1.23 | 2021 年 3 月 22 日 |
0.1.20 | 2020 年 12 月 31 日 |
0.1.19 | 2020 年 10 月 5 日 |
0.1.15 | 2020 年 3 月 31 日 |
#184 在 图形 API 中
每月 1,848 次下载
用于 15 个 Crates(直接使用 2 个)
140KB
3.5K SLoC
Miniquad
在不需要深层依赖树和数千行代码来使用计算机绘制东西的世界里,Miniquad 是一个梦想的实现。
Miniquad 旨在提供一种图形抽象,在具有 GPU 的任何平台上工作方式相同,尽可能轻量,同时覆盖尽可能多的机器。
支持的平台
- Windows,OpenGL 3,OpenGL 2.2;
- Linux,OpenGL 2.2,OpenGL 3,GLES 2,GLES 3;
- macOS,OpenGL 3,Metal;
- iOS,GLES 2,GLES 3,Metal;
- WASM,WebGL 1 - 在 iOS Safari、Firefox、Chrome 上测试过;
- Android,GLES 2,GLES 3。
示例
examples/quad.rs: web 示例
examples/offscreen.rs: web 示例
PonasKovas/miniquad-mandelbrot: web 示例
构建示例
Linux
cargo run --example quad
在 NixOS Linux 上,您可以使用 shell.nix
启动一个开发环境,在其中可以构建和运行 Miniquad。
Windows
# both MSVC and GNU target is supported:
rustup target add x86_64-pc-windows-msvc
# or
rustup target add x86_64-pc-windows-gnu
cargo run --example quad
WASM
rustup target add wasm32-unknown-unknown
cargo build --example quad --target wasm32-unknown-unknown
然后使用以下 .html 来加载 .wasm
index.html
<html lang="en">
<head>
<meta charset="utf-8">
<title>TITLE</title>
<style>
html,
body,
canvas {
margin: 0px;
padding: 0px;
width: 100%;
height: 100%;
overflow: hidden;
position: absolute;
background: black;
z-index: 0;
}
</style>
</head>
<body>
<canvas id="glcanvas" tabindex='1'></canvas>
<!-- Minified and statically hosted version of https://github.com/not-fl3/miniquad/blob/master/native/sapp-wasm/js/gl.js -->
<script src="https://not-fl3.github.io/miniquad-samples/gl.js"></script>
<script>load("quad.wasm");</script> <!-- Your compiled wasm file -->
</body>
</html>
提供静态 .wasm 和 .html 的一种方法
cargo install basic-http-server
basic-http-server .
Android
构建 Android 的推荐方法是使用 Docker。
miniquad 使用稍作修改的 cargo-apk
版本
docker run --rm -v $(pwd)":/root/src" -w /root/src notfl3/cargo-apk cargo quad-apk build --example quad
APK 文件将在 target/android-artifacts/(debug|release)/apk
启用 "log-impl" 后,所有日志调用将被转发到 adb 控制台。无需对 Android 进行代码修改,一切应该都能正常工作。
iOS
在模拟器上运行
mkdir MyGame.app
cargo build --target x86_64-apple-ios --release
cp target/release/mygame MyGame.app
# only if the game have any assets
cp -r assets MyGame.app
cat > MyGame.app/Info.plist << EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>mygame</string>
<key>CFBundleIdentifier</key>
<string>com.mygame</string>
<key>CFBundleName</key>
<string>mygame</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
</dict>
</plist>
EOF
xcrun simctl install booted MyGame.app/
xcrun simctl launch booted com.mygame
有关为真实 iPhone 配置的详细信息和建议,请查看https://macroquad.rs/articles/ios/
交叉编译
# windows target from linux host:
# this is how windows builds are tested from linux machine:
rustup target add x86_64-pc-windows-gnu
cargo run --example quad --target x86_64-pc-windows-gnu
目标
-
快速编译时间。目前从 "cargo clean" 开始大约需要 5 秒,适用于桌面和网页。
-
跨平台。所需平台特定用户代码的量应尽可能少。
-
低端设备支持。
-
可修改性。在制作自己的游戏时,很可能会发现一些硬件兼容性问题。绕过这类错误应该很容易,实现细节不应被抽象层所隐藏。
-
可分支性。每个平台实现通常只是一个纯 Rust 文件。这个文件非常适合复制粘贴 - 它不使用任何 miniquad 特定的抽象。复制 miniquad 的平台实现的一部分并将其单独使用非常容易。
非目标
-
最终类型安全性。库应完全符合 Rust 的安全定义 - 无 UB 或内存不安全。但正确的 GPU 状态不能保证类型正确。用户代码中可以自由提供安全性抽象!
白金赞助商
Miniquad 由以下机构支持