fixed errors and rect positioning

This commit is contained in:
Anton-4 2020-12-12 13:29:43 +01:00
parent 06a2dcb5b7
commit 8ca09dae73
2 changed files with 13 additions and 22 deletions

View file

@ -24,9 +24,9 @@ impl QuadBufferBuilder {
let coords = rect.top_left_coords; let coords = rect.top_left_coords;
self.push_quad( self.push_quad(
coords.x, coords.x,
coords.y - rect.height,
coords.x + rect.width,
coords.y, coords.y,
coords.x + rect.width,
coords.y + rect.height,
rect.color, rect.color,
) )
} }
@ -39,6 +39,10 @@ impl QuadBufferBuilder {
max_y: f32, max_y: f32,
color: [f32; 3], color: [f32; 3],
) -> Self { ) -> Self {
// println!("min_x {:?}", min_x);
// println!("min_y {:?}", min_y);
// println!("max_x {:?}", max_x);
// println!("max_y {:?}", max_y);
self.vertex_data.extend(&[ self.vertex_data.extend(&[
Vertex { Vertex {
position: (min_x, min_y).into(), position: (min_x, min_y).into(),
@ -90,21 +94,9 @@ pub fn create_rect_buffers(
) -> RectBuffers { ) -> RectBuffers {
// Test Rectangles // Test Rectangles
let test_rect_1 = Rect { let test_rect_1 = Rect {
top_left_coords: (-0.2, 0.6).into(), top_left_coords: (0.0, 0.0).into(),
width: 0.1, width: 400.0,
height: 0.5, height: 300.0,
color: [0.0, 0.0, 1.0],
};
let test_rect_2 = Rect {
top_left_coords: (-0.5, 0.0).into(),
width: 0.5,
height: 0.5,
color: [0.0, 1.0, 0.0],
};
let test_rect_3 = Rect {
top_left_coords: (0.3, 0.3).into(),
width: 0.6,
height: 0.1,
color: [1.0, 0.0, 0.0], color: [1.0, 0.0, 0.0],
}; };
@ -127,8 +119,6 @@ pub fn create_rect_buffers(
let num_rects = { let num_rects = {
let (stg_vertex, stg_index, num_indices) = QuadBufferBuilder::new() let (stg_vertex, stg_index, num_indices) = QuadBufferBuilder::new()
.push_rect(&test_rect_1) .push_rect(&test_rect_1)
.push_rect(&test_rect_2)
.push_rect(&test_rect_3)
.build(&gpu_device); .build(&gpu_device);
stg_vertex.copy_to_buffer(encoder, &vertex_buffer); stg_vertex.copy_to_buffer(encoder, &vertex_buffer);

View file

@ -71,7 +71,7 @@ impl Uniforms {
far: 1.0, far: 1.0,
} }
.into(); .into();
println!("{:?}", ortho);
Self { Self {
ortho: ortho.into(), ortho: ortho.into(),
} }
@ -124,6 +124,7 @@ fn run_event_loop() -> Result<(), Box<dyn Error>> {
// Prepare swap chain // Prepare swap chain
let render_format = wgpu::TextureFormat::Bgra8UnormSrgb; let render_format = wgpu::TextureFormat::Bgra8UnormSrgb;
let mut size = window.inner_size(); let mut size = window.inner_size();
println!("size: {:?}", size);
let swap_chain_descr = wgpu::SwapChainDescriptor { let swap_chain_descr = wgpu::SwapChainDescriptor {
usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT, usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT,
@ -229,7 +230,7 @@ fn run_event_loop() -> Result<(), Box<dyn Error>> {
if rect_buffers.num_rects > 0 { if rect_buffers.num_rects > 0 {
render_pass.set_pipeline(&rect_pipeline); render_pass.set_pipeline(&rect_pipeline);
render_pass.set_bind_group(1, &ortho_bind_group, &[]); render_pass.set_bind_group(0, &ortho_bind_group, &[]);
render_pass.set_vertex_buffer(0, rect_buffers.vertex_buffer.slice(..)); render_pass.set_vertex_buffer(0, rect_buffers.vertex_buffer.slice(..));
render_pass.set_index_buffer(rect_buffers.index_buffer.slice(..)); render_pass.set_index_buffer(rect_buffers.index_buffer.slice(..));
render_pass.draw_indexed(0..rect_buffers.num_rects, 0, 0..1); render_pass.draw_indexed(0..rect_buffers.num_rects, 0, 0..1);
@ -314,7 +315,7 @@ fn make_rect_pipeline(
&ortho_bind_group_layout &ortho_bind_group_layout
], ],
push_constant_ranges: &[], push_constant_ranges: &[],
label: Some("Pipeline Layout"), label: Some("Rectangle Pipeline Layout"),
}); });
let pipeline = create_render_pipeline( let pipeline = create_render_pipeline(
&gpu_device, &gpu_device,