#pixel #bevy #graphics #2d #framebuffer #bevy-plugin

bevy_pixels

使用Pixels(一个小型像素缓冲区)进行渲染的Bevy插件

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 渲染

MIT/Apache

17KB
215

bevy_pixels

Bevy插件,使用Pixels(一个小型像素缓冲区)进行渲染

crates.io Bevy tracking

用法

bevybevy_pixels添加到Cargo.toml。请确保禁用bevyrenderbevy_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示例的更高级示例。它演示了将动态内容渲染到像素缓冲区以及为主窗口自定义PixelsPluginPixelsOptions配置。

bounce example

在本地运行示例

使用 just 构建 和 运行示例。有关更多详情,请参阅 Justfile。使用以下命令安装 justcargo 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 来运行示例。

许可证

以下任一许可证下授权:

任选其一。

贡献

除非您明确声明,否则您有意提交以包含在此作品中的任何贡献,均应按上述方式双授权,无需任何额外条款或条件。

依赖项

~25–66MB
~1M SLoC