Added better error handling
This commit is contained in:
parent
e4b1917333
commit
dc6fc474be
8 changed files with 136 additions and 105 deletions
|
|
@ -1,12 +1,12 @@
|
|||
use softbuffer::GraphicsContext;
|
||||
use winit::event::{Event, WindowEvent};
|
||||
use winit::event_loop::{ControlFlow, EventLoop};
|
||||
use winit::window::WindowBuilder;
|
||||
use softbuffer::GraphicsContext;
|
||||
|
||||
fn main() {
|
||||
let event_loop = EventLoop::new();
|
||||
let window = WindowBuilder::new().build(&event_loop).unwrap();
|
||||
let mut graphics_context = unsafe { GraphicsContext::new(window) };
|
||||
let mut graphics_context = unsafe { GraphicsContext::new(window) }.unwrap();
|
||||
|
||||
event_loop.run(move |event, _, control_flow| {
|
||||
*control_flow = ControlFlow::Wait;
|
||||
|
|
@ -17,27 +17,29 @@ fn main() {
|
|||
let size = graphics_context.window().inner_size();
|
||||
(size.width, size.height)
|
||||
};
|
||||
let buffer = (0..((width*height) as usize)).map(|index|{
|
||||
let y = index / (width as usize);
|
||||
let x = index % (width as usize);
|
||||
let red = x % 255;
|
||||
let green = y % 255;
|
||||
let blue = (x*y) % 255;
|
||||
let buffer = (0..((width * height) as usize))
|
||||
.map(|index| {
|
||||
let y = index / (width as usize);
|
||||
let x = index % (width as usize);
|
||||
let red = x % 255;
|
||||
let green = y % 255;
|
||||
let blue = (x * y) % 255;
|
||||
|
||||
let color = blue | (green << 8) | (red << 16);
|
||||
let color = blue | (green << 8) | (red << 16);
|
||||
|
||||
color as u32
|
||||
}).collect::<Vec<_>>();
|
||||
color as u32
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
graphics_context.set_buffer(&buffer, width as u16, height as u16);
|
||||
}
|
||||
Event::WindowEvent {
|
||||
event: WindowEvent::CloseRequested,
|
||||
window_id
|
||||
window_id,
|
||||
} if window_id == graphics_context.window().id() => {
|
||||
*control_flow = ControlFlow::Exit;
|
||||
},
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue