Basic clear screen

This commit is contained in:
Jarrod Doyle 2024-04-25 20:41:55 +01:00
parent 9d332655be
commit 0ee15a1c06
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
1 changed files with 47 additions and 2 deletions

View File

@ -1,5 +1,47 @@
use anyhow::Result;
use crawl::winit::event::{Event, WindowEvent};
use crawl::{
wgpu,
winit::event::{Event, WindowEvent},
};
fn render(ctx: &mut crawl::Context) -> Result<()> {
let frame = ctx.surface.get_current_texture()?;
let view = frame
.texture
.create_view(&wgpu::TextureViewDescriptor::default());
let mut encoder = ctx
.device
.create_command_encoder(&wgpu::CommandEncoderDescriptor {
label: Some("Base Render Encoder"),
});
let _render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("Render Pass"),
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: &view,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(wgpu::Color {
r: 0.4,
g: 0.4,
b: 0.4,
a: 1.0,
}),
store: wgpu::StoreOp::Store,
},
})],
depth_stencil_attachment: None,
occlusion_query_set: None,
timestamp_writes: None,
});
drop(_render_pass);
ctx.queue.submit(Some(encoder.finish()));
frame.present();
Ok(())
}
fn main() -> Result<()> {
env_logger::init();
@ -17,7 +59,10 @@ fn main() -> Result<()> {
}
if let WindowEvent::RedrawRequested = event {
log::info!("Epic");
if let Err(err) = render(&mut context) {
log::error!("{err:?}");
}
context.window.request_redraw();
}
}