From be20f3ae2a6880134f807a0fb41abc5e8e3ea096 Mon Sep 17 00:00:00 2001 From: mitchellhansen Date: Sun, 11 Aug 2019 21:30:44 -0700 Subject: [PATCH] sprites are working, but the implementation is pretty bad --- resources/shaders/color-passthrough.vertex | 2 +- src/main.rs | 4 +++- src/sprite.rs | 12 ++++++------ src/util/shader_kernels.rs | 2 +- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/resources/shaders/color-passthrough.vertex b/resources/shaders/color-passthrough.vertex index 74366ae5..feeaab0e 100644 --- a/resources/shaders/color-passthrough.vertex +++ b/resources/shaders/color-passthrough.vertex @@ -5,7 +5,7 @@ layout(location = 1) in vec4 color; layout(location = 0) out vec4 out_color; void main() { - // out_color = color; + out_color = color; gl_Position = vec4(position, 0.0, 1.0); } diff --git a/src/main.rs b/src/main.rs index a97003e0..63168202 100644 --- a/src/main.rs +++ b/src/main.rs @@ -63,7 +63,8 @@ fn main() { let mut mouse_xy = Vector2i::new(0,0); - let sprite = Sprite::new_with_color((0.,0.), (0,0), (0.,0.,0.,0.)); + let sprite = Sprite::new_with_color((0.,0.), (0.1,0.1), (1.,0.,0.,1.)); + let sprite2 = Sprite::new_with_color((-1.,-0.5), (0.1,0.1), (0.,1.,0.,1.)); while let Some(p) = window.get_position() { @@ -113,6 +114,7 @@ fn main() { let mut canvas = CanvasFrame::new(); canvas.draw(&sprite); + canvas.draw(&sprite2); (frame_future) = processor.run(&surface, frame_future, canvas); } diff --git a/src/sprite.rs b/src/sprite.rs index 9d0adaa3..55672b92 100644 --- a/src/sprite.rs +++ b/src/sprite.rs @@ -5,7 +5,7 @@ pub struct Sprite { pub vertices: [(f32, f32); 6], position: (f32, f32), - size: (u32, u32), + size: (f32, f32), color: (f32, f32, f32, f32), textured: bool, @@ -16,11 +16,11 @@ pub struct Sprite { impl Sprite { - pub fn new(position: (f32, f32), size: (u32, u32)) -> Sprite { + pub fn new(position: (f32, f32), size: (f32, f32)) -> Sprite { Sprite::new_with_color(position, size, (0.,0.,0.,0.)) } - pub fn new_with_color(position: (f32, f32), size: (u32, u32), color: (f32, f32, f32, f32)) -> Sprite { + pub fn new_with_color(position: (f32, f32), size: (f32, f32), color: (f32, f32, f32, f32)) -> Sprite { let fsize = (size.0 as f32, size.1 as f32); @@ -42,7 +42,7 @@ impl Sprite { } } - pub fn new_with_texture(position: (f32, f32), size: (u32, u32), texture_id: String) -> Sprite { + pub fn new_with_texture(position: (f32, f32), size: (f32, f32), texture_id: String) -> Sprite { let fsize = (size.0 as f32, size.1 as f32); @@ -55,8 +55,8 @@ impl Sprite { (position.0 + fsize.0, position.1 + fsize.1 ), // bottom right (position.0 + fsize.0, position.1 ), // top right ], - position, - size, + position: position, + size: size, color: (0.0, 0.0, 0.0, 0.0), textured: false, texture_id: Some(texture_id) diff --git a/src/util/shader_kernels.rs b/src/util/shader_kernels.rs index 0f5eb18f..e1a11c80 100644 --- a/src/util/shader_kernels.rs +++ b/src/util/shader_kernels.rs @@ -175,7 +175,7 @@ impl ShaderKernels { third_constant: 0.0, }) - .triangle_fan() + .triangle_list() // Use a resizable viewport set to draw over the entire window .viewports_dynamic_scissors_irrelevant(1)