still dont know why this isn't working

This commit is contained in:
2019-06-18 23:55:21 -07:00
parent 6698c04b58
commit 4de26c702d
2 changed files with 28 additions and 14 deletions

View File

@@ -60,7 +60,7 @@ impl<'t> Edge<'t> {
let mut surface = RenderTexture::new(800, 600, false).unwrap();
surface.set_smooth(true);
let mut bg_sprite = Sprite::with_texture(bg_texture);
bg_sprite.set_position((135., 100.));
bg_sprite.set_position((0., 0.));
let mut entities = Vec::new();
for i in 0..6 {
@@ -174,7 +174,12 @@ fn main() {
let mut img = image::open("resources/images/funky-bird.jpg").unwrap();
let xy = img.dimensions();
let data_length = xy.0*xy.1*3;
println!("Buffer length {}", data_length);
println!("Buffer length {}", img.raw_pixels().len());
println!("Size {:?}", xy);
let mut image_buffer = Vec::new();
{
// Pull out the image data and place it in a sync'd CPU<->GPU buffer
@@ -193,7 +198,7 @@ fn main() {
// The command buffer I think pretty much serves to define what runs where for how many times
let command_buffer = AutoCommandBufferBuilder::primary_one_time_submit(device.clone(), queue.family()).unwrap()
.dispatch([1024, 1, 1], pipeline.clone(), set.clone(), ()).unwrap()
.dispatch([xy.0, xy.1, 1], pipeline.clone(), set.clone(), ()).unwrap()
.build().unwrap();
// Create a future for running the command buffer and then just fence it
@@ -202,22 +207,25 @@ fn main() {
.then_signal_fence_and_flush().unwrap();
// I think this is redundant and returns immediately
future.wait(None).unwrap();
// future.wait(None).unwrap();
// The buffer is sync'd so we can just read straight from the handle
let data_buffer_content = data_buffer.read().unwrap();
//
for x in 0 .. xy.0 {
for y in 0 .. xy.1 {
for y in 0 .. xy.1 {
for x in 0 .. xy.0 {
let r = data_buffer_content[((xy.0 * y + x) * 3 + 0) as usize] as u8;
let g = data_buffer_content[((xy.0 * y + x) * 3 + 1) as usize] as u8;
let b = data_buffer_content[((xy.0 * y + x) * 3 + 2) as usize] as u8;
// let a = data_buffer_content[((xy.0 * y + x) * 4 + 3) as usize] as u8;
let old = img.get_pixel(x, y);
img.put_pixel(x, y, image::Rgba([r, g, b, 0]));
image_buffer.push(r);
image_buffer.push(g);
image_buffer.push(b);
image_buffer.push(255);
img.put_pixel(x, y, image::Rgba([r, g, b, 255]))
}
}
}
@@ -227,7 +235,7 @@ fn main() {
println!("Starting");
let mut window = RenderWindow::new(
(512, 512),
(900, 900),
"Custom drawable",
Style::CLOSE,
&Default::default(),
@@ -239,7 +247,9 @@ fn main() {
//==========================================
let font = Font::from_file("resources/fonts/sansation.ttf").unwrap();
let mut bg_texture = Texture::from_file("output.png").unwrap();
let mut bg_texture = Texture::new(xy.0, xy.1).unwrap();
bg_texture.update_from_pixels(image_buffer.as_slice(), xy.0, xy.1, 0, 0);
//let mut bg_texture = Texture::from_file("resources/images/sfml.png").unwrap();
//bg_texture.set_smooth(true);