Comments (5)
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.
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.
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.
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.
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)
- Ability to customize underlying components during setup HOT 15
- Update to bevy 0.10 HOT 1
- Benchmarks HOT 1
- Mouse Position Example HOT 1
- Update to bevy 0.11 HOT 1
- Fix `do_resize_sprite` test
- Error printed every frame in some GPUs HOT 2
- The pixel buffer with a attached compute shader is never rendered when setting pixel buffer size
- fill_egui example not working HOT 6
- Adjust pixel size HOT 2
- Can I get the texture from a shader and draw it on the screen with egui? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bevy_pixel_buffer.