[oden] Challenge for step 2
This commit is contained in:
parent
a03c119b4c
commit
f0778f047a
1 changed files with 24 additions and 3 deletions
27
src/lib.rs
27
src/lib.rs
|
|
@ -12,8 +12,12 @@ struct State {
|
|||
config: wgpu::SurfaceConfiguration,
|
||||
size: winit::dpi::PhysicalSize<u32>,
|
||||
window: Window,
|
||||
mouse_x: f64,
|
||||
mouse_y: f64,
|
||||
}
|
||||
|
||||
// TUTORIAL FOR BABIES LIKE ME: https://sotrh.github.io/learn-wgpu/beginner/tutorial2-surface/
|
||||
|
||||
impl State {
|
||||
// Creating some of the wgpu types requires async code
|
||||
async fn new(window: Window) -> Self {
|
||||
|
|
@ -89,6 +93,8 @@ impl State {
|
|||
queue,
|
||||
config,
|
||||
size,
|
||||
mouse_x: 0.0,
|
||||
mouse_y: 0.0,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -123,6 +129,11 @@ impl State {
|
|||
});
|
||||
|
||||
{
|
||||
// BEGIN GARBAGE
|
||||
let r: f64 = (self.mouse_x / f64::from(self.size.width)).clamp(0.0, 1.0) * 0.1;
|
||||
let g: f64 = (self.mouse_y / f64::from(self.size.height)).clamp(0.0, 1.0) * 0.2;
|
||||
// END GARBAGE
|
||||
|
||||
let _render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||
label: Some("Render Pass"),
|
||||
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
|
||||
|
|
@ -130,8 +141,8 @@ impl State {
|
|||
resolve_target: None,
|
||||
ops: wgpu::Operations {
|
||||
load: wgpu::LoadOp::Clear(wgpu::Color {
|
||||
r: 0.1,
|
||||
g: 0.2,
|
||||
r, //0.1,
|
||||
g, //0.2,
|
||||
b: 0.3,
|
||||
a: 1.0,
|
||||
}),
|
||||
|
|
@ -142,7 +153,7 @@ impl State {
|
|||
});
|
||||
}
|
||||
|
||||
// submit will accept anything that implements IntoIter
|
||||
// Submit will accept anything that implements IntoIter
|
||||
self.queue.submit(std::iter::once(encoder.finish()));
|
||||
output.present();
|
||||
|
||||
|
|
@ -157,6 +168,10 @@ pub async fn run() {
|
|||
|
||||
let mut state = State::new(window).await;
|
||||
|
||||
// NOTE: There's some well-understood way here of doing constant
|
||||
// rendering rather than being driven by events but I removed it
|
||||
// for now. I will have to find it again at some point.
|
||||
|
||||
event_loop.run(move |event, _, control_flow| match event {
|
||||
Event::WindowEvent {
|
||||
ref event,
|
||||
|
|
@ -175,6 +190,12 @@ pub async fn run() {
|
|||
..
|
||||
} => *control_flow = ControlFlow::Exit,
|
||||
|
||||
WindowEvent::CursorMoved { position, .. } => {
|
||||
state.mouse_x = position.x;
|
||||
state.mouse_y = position.y;
|
||||
state.window().request_redraw();
|
||||
}
|
||||
|
||||
WindowEvent::Resized(physical_size) => {
|
||||
state.resize(*physical_size);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue