<div align="center">
<h1>
bevy_pixels
</h1>
<p>
<strong>
<a href="https://github.com/bevyengine/bevy">Bevy</a> plugin that uses
<a href="https://github.com/parasyte/pixels">Pixels</a> (a tiny pixel buffer) for rendering
</strong>
</p>
<p>
<a href="https://github.com/dtcristo/bevy_pixels#license">
<img src="https://img.shields.io/badge/license-MIT%2FApache-blue.svg" alt="License" />
</a>
<a href="https://crates.io/crates/bevy_pixels">
<img src="https://img.shields.io/crates/v/bevy_pixels.svg" alt="crates.io" />
</a>
<a href="https://docs.rs/bevy_pixels">
<img src="https://docs.rs/bevy_pixels/badge.svg" alt="Docs" />
</a>
<a
href="https://bevyengine.org/learn/quick-start/plugin-development/#main-branch-tracking"
>
<img
src="https://img.shields.io/badge/Bevy%20tracking-released%20version-lightblue"
alt="Following released Bevy versions"
/>
</a>
</p>
</div>
## Usage
Add `bevy` and `bevy_pixels` to `Cargo.toml`. Be sure to disable `bevy`'s `render` and `bevy_wgpu` features (with `default-features = false`) as they will conflict with rendering provided by `bevy_pixels`.
```toml
[dependencies]
bevy = { version = "0.18", default-features = false }
bevy_pixels = "0.16"
```
Add `PixelsPlugin` to your Bevy project.
```rust
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();
}
```
Use Bevy's `Single` system param in systems that target the single-window case.
```rust
fn draw(mut wrapper: Single<&mut PixelsWrapper>) {
// Get a mutable slice for the pixel buffer.
let frame: &mut [u8] = wrapper.pixels.frame_mut();
// Fill frame with pixel data.
// ...
}
```
## Bevy and Pixels version mapping
| bevy_pixels | bevy | pixels |
| 0.15 | 0.15 | 0.15 |
| 0.14 | 0.14 | 0.15 |
| 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 |
## Examples
### [minimal](https://github.com/dtcristo/bevy_pixels/blob/main/examples/minimal/src/main.rs)
This example demonstrates rendering a solid color to the pixel buffer.
### [multiple_windows](https://github.com/dtcristo/bevy_pixels/blob/main/examples/multiple_windows/src/main.rs)
This example demonstrate usage of multiple windows each with their own pixel buffer.
### [custom_render](https://github.com/dtcristo/bevy_pixels/blob/main/examples/custom_render/src/main.rs)
This example demonstrate usage of a custom render system. Default `render` cargo feature must be disabled before defining a custom render system. Use `default-features = false` in Cargo.toml.
### [bounce](https://github.com/dtcristo/bevy_pixels/blob/main/examples/bounce/src/main.rs)
More advanced example based off the [`minimal-winit`](https://github.com/parasyte/pixels/tree/master/examples/minimal-winit) example from the pixels project. It demonstrates rendering dynamic content to the pixel buffer as well as custom configuration for `PixelsPlugin` and `PixelsOptions` on the primary window.

### [mandelbrot](https://github.com/dtcristo/bevy_pixels/blob/main/examples/mandelbrot/src/main.rs)
Simple colorful fractal example that demonstrates interactive rendering with `bevy_pixels`. Left click zooms in on the clicked point, right click zooms back out, the native window is resizable without changing the zoom level, and the web build fills the browser viewport.

### Running examples natively
Build and run example with [just](https://github.com/casey/just). See [`Justfile`](Justfile) for more details. Install `just` with `cargo install just`.
```sh
just run example_name
```
### Running examples in web browser
Install dependencies.
```sh
rustup target add wasm32-unknown-unknown
cargo install wasm-bindgen-cli miniserve
```
Build and serve example for web.
```sh
just serve-web example_name
```
Open [localhost:8080](http://localhost:8080/) in your web browser to run the example.
## License
Licensed under either of
- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE))
- MIT License ([LICENSE-MIT](LICENSE-MIT))
at your option.
## Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you shall be dual licensed as above, without any
additional terms or conditions.