mirror of
https://github.com/italicsjenga/rust_minifb.git
synced 2024-12-23 19:31:30 +11:00
8b3c2e9b37
* Deprecated update_with_buffer and added a temporary (update_with_buffer_size) for now. This will later be removed and the update_with_buffer is requiring the size to bu suplied * Reparation for 0.14 release * Missed one case * Minor cleanup * Switch to C scalar for Unix + rename Reason is so we can always use optimized scalar even in debug. Also removed _size so only update_with_buffer(..) takes width, height of the input buffer * Implemented AspectRatio aware scale on nix * Implemented image center * Added UpperLeft center mode for unix * Moving macOS over to sized update * Fixed resize not working on macOS * WIP on macOS * More WIP on macOS version * Bunch of macOS updates and fixes * Fixed broken bg color on macOS * Windows fixes WIP * Remove some spamming * More windows fixes * Windows fixes for cursor and warnings * Some cleanup * rustfmt pass * Fixed typo * Added support for limiting update rate * Added update rate to Windows * Added update rate to macOS * Misc fixes * Fixed resources and maintance badge * Updated readme * Updated changelog * Added rate limit
43 lines
1.4 KiB
Rust
43 lines
1.4 KiB
Rust
extern crate minifb;
|
|
extern crate png;
|
|
|
|
use minifb::{Key, ScaleMode, Window, WindowOptions};
|
|
|
|
fn main() {
|
|
use std::fs::File;
|
|
// The decoder is a build for reader and can be used to set various decoding options
|
|
// via `Transformations`. The default output transformation is `Transformations::EXPAND
|
|
// | Transformations::STRIP_ALPHA`.
|
|
let decoder = png::Decoder::new(File::open("resources/uv.png").unwrap());
|
|
let (info, mut reader) = decoder.read_info().unwrap();
|
|
// Allocate the output buffer.
|
|
let mut buf = vec![0; info.buffer_size()];
|
|
// Read the next frame. Currently this function should only called once.
|
|
// The default options
|
|
reader.next_frame(&mut buf).unwrap();
|
|
// convert buffer to u32
|
|
|
|
let u32_buffer: Vec<u32> = buf
|
|
.chunks(3)
|
|
.map(|v| ((v[0] as u32) << 16) | ((v[1] as u32) << 8) | v[2] as u32)
|
|
.collect();
|
|
|
|
let mut window = Window::new(
|
|
"Noise Test - Press ESC to exit",
|
|
info.width as usize,
|
|
info.height as usize,
|
|
WindowOptions {
|
|
resize: true,
|
|
scale_mode: ScaleMode::Center,
|
|
..WindowOptions::default()
|
|
},
|
|
)
|
|
.expect("Unable to open Window");
|
|
|
|
while window.is_open() && !window.is_key_down(Key::Escape) {
|
|
window
|
|
.update_with_buffer(&u32_buffer, info.width as usize, info.height as usize)
|
|
.unwrap();
|
|
}
|
|
}
|