Expand description
A bevy library to manage and draw a bunch of pixels.
§Example
use bevy::prelude::*;
use bevy_pixel_buffer::prelude::*;
fn main() {
let size = PixelBufferSize {
size: UVec2::new(32, 32),
pixel_size: UVec2::new(16, 16),
};
App::new()
.add_plugins((DefaultPlugins, PixelBufferPlugin))
.add_systems(Startup, pixel_buffer_setup(size))
.add_systems(Update, update)
.run();
}
fn update(mut pb: QueryPixelBuffer) {
pb.frame().per_pixel(|_, _| Pixel::random());
}
See other examples.
§Quick how to
§Create a pixel buffer
Probably PixelBufferBuilder is your friend, but if you like the more bevy like experience of working with bundles, see the bundle module.
§Get the pixel buffer in your systems
There are 2 approaches:
- Create your custom bevy queries. A pixel buffer is composed of a PixelBuffer, Handle<Image> and optionally a EguiTexture and Handle<ComputeShader> components.
- Use the premade queries in the query module. This exist for quick prototyping and common queries related to one or more pixel buffers.
§Modify a pixel buffer
The data of the pixels lives inside a bevy Image. To edit it exists the Frame struct. There are many ways to get a Frame.
Once you have a Frame it offers methods to edit the Pixels. The crate does not offer drawing behaviour (yet) for shapes like triangles, quads or anything like that, but with Frame::raw_mut you can implement any behaviour you want.
Re-exports§
pub use bevy_egui;
Modules§
- builder
- Utilities for constructing pixel buffers.
- bundle
- Bundles that can be used to manually create a pixel buffer.
- compute_
shader - Adds a way to easily attach a compute shader to update the pixel buffer every frame.
- egui
- Adds integrations with bevy_egui and other egui types. This modules
requires the
egui
feature. - frame
- Frame and frame utility functions that helps to draw things on raw image data.
- pixel
- Pixel struct with the ability to send it to the GPU.
- pixel_
buffer - Core systems and components of the pixel buffer library
- prelude
- Common imports
- query
- Adds utility queries