Giter VIP home page Giter VIP logo

bevy_pixels's Introduction

bevy_pixels

Bevy plugin that uses Pixels (a tiny pixel buffer) for rendering

crates.io Bevy tracking

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.

[dependencies]
bevy = { version = "0.10", default_features = false }
bevy_pixels = "0.10"

Add PixelsPlugin to your Bevy project.

use bevy::prelude::*;
use bevy_pixels::prelude::*;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_plugin(PixelsPlugin::default())
        // Add systems that draw to the buffer in `PixelsSet::Draw` set (or before)
        // to ensure they are rendered in the current frame.
        .add_system(draw.in_set(PixelsSet::Draw))
        .run();
}

Use PixelsWrapper in your systems.

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 and Pixels version mapping

bevy_pixels bevy pixels
0.1 0.5 0.3
0.2 0.5 0.8
0.3-0.4 0.6 0.9
0.5 0.7 0.9
0.6 0.8 0.10
0.7 0.9 0.10
0.8 0.9 0.11
0.9-0.10 0.10 0.12

Examples

This example demonstrates rendering a solid color to the pixel buffer.

This example demonstrate usage of multiple windows each with their own pixel buffer.

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.

More advanced example based off the 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.

bounce example

Running examples natively

Build and run example with just. See Justfile for more details. Install just with cargo install just.

just run example_name

Running examples in web browser

Install dependencies.

rustup target add wasm32-unknown-unknown
cargo install wasm-bindgen-cli miniserve

Build and serve example for web.

just serve-web example_name

Open localhost:8080 in your web browser to run the example.

License

Licensed under either of

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.