Added fruit example to show a more recognizable image for debugging
This commit is contained in:
parent
b5573de387
commit
a23b7f9876
4 changed files with 45 additions and 1 deletions
|
|
@ -17,4 +17,5 @@ x11-dl = "2.19.1"
|
||||||
winapi = "0.3.9"
|
winapi = "0.3.9"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
winit = "0.26.1"
|
winit = "0.26.1"
|
||||||
|
image = "0.23.14"
|
||||||
BIN
examples/fruit.jpg
Normal file
BIN
examples/fruit.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 113 KiB |
5
examples/fruit.jpg.license
Normal file
5
examples/fruit.jpg.license
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
fruit.jpg is licensed under the Creative Commons Attribution 3.0 Unported license and was put on Wikimedia by user Atomcibre
|
||||||
|
|
||||||
|
Source: https://commons.wikimedia.org/wiki/File:Culinary_fruits_front_view.jpg
|
||||||
|
|
||||||
|
License: https://creativecommons.org/licenses/by/3.0/deed.en
|
||||||
38
examples/fruit.rs
Normal file
38
examples/fruit.rs
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
use image::GenericImageView;
|
||||||
|
use softbuffer::GraphicsContext;
|
||||||
|
use winit::event::{Event, WindowEvent};
|
||||||
|
use winit::event_loop::{ControlFlow, EventLoop};
|
||||||
|
use winit::window::WindowBuilder;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
//see fruit.jpg.license for the license of fruit.jpg
|
||||||
|
let fruit = image::load_from_memory(include_bytes!("fruit.jpg")).unwrap();
|
||||||
|
let buffer = fruit.pixels().map(|(_x, _y, pixel)|{
|
||||||
|
let red = pixel.0[0] as u32;
|
||||||
|
let green = pixel.0[1] as u32;
|
||||||
|
let blue = pixel.0[2] as u32;
|
||||||
|
|
||||||
|
blue | (green << 8) | (red << 16)
|
||||||
|
}).collect::<Vec<_>>();
|
||||||
|
|
||||||
|
let event_loop = EventLoop::new();
|
||||||
|
let window = WindowBuilder::new().build(&event_loop).unwrap();
|
||||||
|
let mut graphics_context = unsafe { GraphicsContext::new(window) }.unwrap();
|
||||||
|
|
||||||
|
event_loop.run(move |event, _, control_flow| {
|
||||||
|
*control_flow = ControlFlow::Wait;
|
||||||
|
|
||||||
|
match event {
|
||||||
|
Event::RedrawRequested(window_id) if window_id == graphics_context.window().id() => {
|
||||||
|
graphics_context.set_buffer(&buffer, fruit.width() as u16, fruit.height() as u16);
|
||||||
|
}
|
||||||
|
Event::WindowEvent {
|
||||||
|
event: WindowEvent::CloseRequested,
|
||||||
|
window_id,
|
||||||
|
} if window_id == graphics_context.window().id() => {
|
||||||
|
*control_flow = ControlFlow::Exit;
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue