12个重大版本发布
0.13.0 | 2024年3月26日 |
---|---|
0.12.0 | 2023年11月23日 |
0.11.0 | 2023年7月18日 |
0.9.0 | 2023年3月29日 |
0.1.1 | 2021年5月30日 |
#241 in 渲染
17KB
215 行
用法
将bevy
和bevy_pixels
添加到Cargo.toml
。请确保禁用bevy
的render
和bevy_wgpu
功能(使用default-features = false
),因为它们将与bevy_pixels
提供的渲染冲突。
[dependencies]
bevy = { version = "0.13", default_features = false }
bevy_pixels = "0.13"
将PixelsPlugin
添加到您的Bevy项目中。
use bevy::prelude::*;
use bevy_pixels::prelude::*;
fn main() {
App::new()
.add_plugins((DefaultPlugins, PixelsPlugin::default()))
// Add systems that draw to the buffer to `Draw` schedule
// to ensure they are rendered in the current frame.
.add_systems(Draw, draw)
.run();
}
在您的系统中使用PixelsWrapper
。
fn draw(mut wrapper_query: Query<&mut PixelsWrapper>) {
// Query the `PixelsWrapper` component that owns an instance of `Pixels` for the given window.
let Ok(mut wrapper) = wrapper_query.get_single_mut() else { return };
// Get a mutable slice for the pixel buffer.
let frame: &mut [u8] = wrapper.pixels.frame_mut();
// Fill frame with pixel data.
// ...
}
Bevy和Pixels版本映射
bevy_pixels | bevy | pixels |
---|---|---|
0.13 | 0.13 | 0.13 |
0.12 | 0.12 | 0.13 |
0.11 | 0.11 | 0.13 |
0.9-0.10 | 0.10 | 0.12 |
0.8 | 0.9 | 0.11 |
0.7 | 0.9 | 0.10 |
0.6 | 0.8 | 0.10 |
0.5 | 0.7 | 0.9 |
0.3-0.4 | 0.6 | 0.9 |
0.2 | 0.5 | 0.8 |
0.1 | 0.5 | 0.3 |
示例
minimal
此示例演示了将纯色渲染到像素缓冲区。
multiple_windows
此示例演示了使用具有自己像素缓冲区的多个窗口的用法。
custom_render
此示例演示了自定义渲染系统的用法。在定义自定义渲染系统之前,必须禁用默认的render
cargo功能。在Cargo.toml中使用default_features = "false"
。
bounce
基于pixels项目中的minimal-winit
示例的更高级示例。它演示了将动态内容渲染到像素缓冲区以及为主窗口自定义PixelsPlugin
和PixelsOptions
配置。
在本地运行示例
使用 just 构建 和 运行示例。有关更多详情,请参阅 Justfile
。使用以下命令安装 just
: cargo install just
。
just run example_name
在网页浏览器中运行示例
安装依赖。
rustup target add wasm32-unknown-unknown
cargo install wasm-bindgen-cli miniserve
构建并服务于网页示例。
just serve-web example_name
在您的网页浏览器中打开 localhost:8080 来运行示例。
许可证
以下任一许可证下授权:
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT License (LICENSE-MIT)
任选其一。
贡献
除非您明确声明,否则您有意提交以包含在此作品中的任何贡献,均应按上述方式双授权,无需任何额外条款或条件。
依赖项
~25–66MB
~1M SLoC