fixed depth buffering for images

This commit is contained in:
2019-09-11 22:39:25 -07:00
parent f6adbd80d1
commit df2543bc8d
7 changed files with 70 additions and 80 deletions

View File

@@ -4,7 +4,7 @@ use std::sync::Arc;
#[derive(Debug, Clone)]
pub struct Sprite {
pub vertices: [(f32, f32); 6],
pub vertices: [(f32, f32, f32); 6],
pub ti_position: [(f32, f32); 6],
position: (f32, f32),
@@ -20,23 +20,24 @@ pub struct Sprite {
impl Sprite {
pub fn new(position: (f32, f32), size: (f32, f32)) -> Sprite {
Sprite::new_with_color(position, size, (0.,0.,0.,0.))
Sprite::new_with_color(position, size, 0, (0.,0.,0.,0.))
}
pub fn new_with_color(position: (f32, f32),
size: (f32, f32),
depth: u32,
color: (f32, f32, f32, f32)) -> Sprite {
let fsize = (size.0 as f32, size.1 as f32);
let normalized_depth = (depth as f32 / 255.0);
Sprite {
vertices: [
(position.0, position.1 ), // top left
(position.0, position.1 + fsize.1), // bottom left
(position.0 + fsize.0, position.1 + fsize.1 ), // bottom right
(position.0, position.1 ), // top left
(position.0 + fsize.0, position.1 + fsize.1 ), // bottom right
(position.0 + fsize.0, position.1 ), // top right
(position.0, position.1 , normalized_depth), // top left
(position.0, position.1 + size.1 , normalized_depth), // bottom left
(position.0 + size.0, position.1 + size.1, normalized_depth), // bottom right
(position.0, position.1 , normalized_depth), // top left
(position.0 + size.0, position.1 + size.1, normalized_depth), // bottom right
(position.0 + size.0, position.1 , normalized_depth), // top right
],
position: position,
@@ -56,18 +57,21 @@ impl Sprite {
}
///
pub fn new_with_texture(position: (f32, f32), size: (f32, f32), texture_handle: Arc<CanvasTextureHandle>) -> Sprite {
pub fn new_with_texture(position: (f32, f32),
size: (f32, f32),
depth: u32,
texture_handle: Arc<CanvasTextureHandle>) -> Sprite {
let fsize = (size.0 as f32, size.1 as f32);
let normalized_depth = (depth as f32 / 255.0);
Sprite {
vertices: [
(position.0, position.1 ), // top left
(position.0, position.1 + fsize.1), // bottom left
(position.0 + fsize.0, position.1 + fsize.1 ), // bottom right
(position.0, position.1 ), // top left
(position.0 + fsize.0, position.1 + fsize.1 ), // bottom right
(position.0 + fsize.0, position.1 ), // top right
(position.0, position.1 , normalized_depth), // top left
(position.0, position.1 + size.1 , normalized_depth), // bottom left
(position.0 + size.0, position.1 + size.1, normalized_depth), // bottom right
(position.0, position.1 , normalized_depth), // top left
(position.0 + size.0, position.1 + size.1, normalized_depth), // bottom right
(position.0 + size.0, position.1 , normalized_depth), // top right
],
position: position,
ti_position: [
@@ -91,7 +95,7 @@ impl Sprite {
impl Drawable for Sprite {
fn get_vertices(&self) -> Vec<(f32,f32)> {
fn get_vertices(&self) -> Vec<(f32,f32,f32)> {
self.vertices.to_vec()
}