Coder Social home page Coder Social logo

Comments (5)

Zheoni avatar Zheoni commented on August 30, 2024 1

Ok, so you were drawing outside of the window. Naming things is hard, but yes, size is not actual screen size, but the size of the buffer, and if the pixels are bigger, they won't fit.

I'm glad you found the solution, good luck with your project 😄

from bevy_pixel_buffer.

Zheoni avatar Zheoni commented on August 30, 2024

Hi! I'm on windows, bevy 0.12.1, and all your update functions work for me.

I've added a new single_pixel example, but it's just the second snippet you posted. Test if the new example works on your system before further investigation. Do it in a clean project or clone the repo and run cargo run --example single_pixel.

from bevy_pixel_buffer.

zanciks avatar zanciks commented on August 30, 2024

Thanks for the speedy reply!
The example actually works great. After running that and debugging my code, it would seem the error is actually coming from how I'm importing DefaultPlugins.

const WIDTH:  f32 = 128.0;
const HEIGHT: f32 = 128.0;

fn main() {
    let size = PixelBufferSize {
        size: UVec2::new(WIDTH as u32, HEIGHT as u32),
        pixel_size: UVec2::new(16, 16),
    };

    App::new()
        .add_plugins(DefaultPlugins.set(
            WindowPlugin {
                primary_window: Some(Window {
                    resolution: WindowResolution::new(WIDTH, HEIGHT),
                    ..default()
                }),
                ..default()
            }
        ))
        .add_plugins(PixelBufferPlugin)
        .add_systems(Startup, pixel_buffer_setup(size))
        .add_systems(Update, update)
        .run();
}

fn update(mut pb: QueryPixelBuffer) {
    let mut frame = pb.frame();
    let mut rng = rand::thread_rng();
    let pos = (
        rng.gen_range(0..frame.size().x),
        rng.gen_range(0..frame.size().y),
    );
    frame.set(pos, Pixel::random()).expect("out of bounds");
}

I'm not getting any errors, but only a few pixels are being changed in frame, and it takes a while.
Changing pos to (5, 5) for instance shows that, even though it SHOULD be in range, it isn't visible.
Is there perhaps a better way to be setting my window resolution that works with this crate?

ie.

fn update(mut pb: QueryPixelBuffer) {
    let mut frame = pb.frame();
    frame.set((5, 5), Pixel::random()).expect("out of bounds");
}

Doesn't set any visible pixel to Pixel::random().

from bevy_pixel_buffer.

zanciks avatar zanciks commented on August 30, 2024

Oh, I think I have found the issue!
I think it was an issue of misunderstanding on my end. I had assumed that no matter what PixelBufferSize.pixel_size was, the first visible pixel would be at (0, 0), however, this isn't the case!
In the code I posted in Comment 3 (just above), the center of the screen is pixel (256, 256) [which is coming from the 512, 512 size].
The area is then 32x32 pixels wide, so the first visible pixel is (256 - 16, 256 - 16) = (240, 240).

My code to change the FIRST pixel is as follows

const WIDTH:  f32 = 512.0;
const HEIGHT: f32 = 512.0;

fn main() {
    let size = PixelBufferSize {
        size: UVec2::new(WIDTH as u32, HEIGHT as u32),
        pixel_size: UVec2::new(16, 16),
    };

    App::new()
        .add_plugins(DefaultPlugins.set(
            WindowPlugin {
                primary_window: Some(Window {
                    resolution: WindowResolution::new(WIDTH, HEIGHT),
                    ..default()
                }),
                ..default()
            }
        ))
        .add_plugins(PixelBufferPlugin)
        .add_systems(Startup, pixel_buffer_setup(size))
        .add_systems(Update, update)
        .run();
}

fn update(mut pb: QueryPixelBuffer) {
    let mut frame = pb.frame();
    frame.set((240, 240), Pixel::random()).expect("No worky!");
}

from bevy_pixel_buffer.

zanciks avatar zanciks commented on August 30, 2024

Simpler thing to do is to read the docs I guess lol

Just needed to not have PixelBufferSize be equal to my screen resolution...

    let size = PixelBufferSize {
        size: UVec2::new(WIDTH as u32 / 4, HEIGHT as u32 / 4),
        pixel_size: UVec2::new(4, 4),
    };

Fixes all problems!

from bevy_pixel_buffer.

Related Issues (12)

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.