parent
cce893a0c8
commit
1f33d96ae5
@ -0,0 +1,34 @@
|
||||
use crate::vertex_2d::ColoredVertex2D;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Sprite {
|
||||
vertices: [ColoredVertex2D; 6],
|
||||
color: [f32; 4],
|
||||
}
|
||||
|
||||
impl Sprite {
|
||||
|
||||
pub fn new(position: (f32, f32), size: (u32, u32)) -> 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 {
|
||||
|
||||
let size = (size.0 as f32, size.1 as f32);
|
||||
|
||||
let color = [color.0, color.1, color.2, color.3];
|
||||
|
||||
Sprite {
|
||||
vertices: [
|
||||
ColoredVertex2D { position: [ position.0, position.1 ], color }, // top left
|
||||
ColoredVertex2D { position: [ position.0, position.1 + size.1], color }, // bottom left
|
||||
ColoredVertex2D { position: [ position.0 + size.0, position.1 + size.1 ], color }, // bottom right
|
||||
|
||||
ColoredVertex2D { position: [ position.0, position.1 ], color }, // top left
|
||||
ColoredVertex2D { position: [ position.0 + size.0, position.1 + size.1 ], color }, // bottom right
|
||||
ColoredVertex2D { position: [ position.0 + size.0, position.1 ], color }, // top right
|
||||
],
|
||||
color: color,
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
|
||||
#[derive(Default, Debug, Clone)]
|
||||
pub struct Vertex2D {
|
||||
pub position: [f32; 2]
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone)]
|
||||
pub struct ColoredVertex2D {
|
||||
pub position: [f32; 2],
|
||||
pub color : [f32; 4],
|
||||
}
|
||||
|
||||
vulkano::impl_vertex!(ColoredVertex2D, position, color);
|
@ -0,0 +1,11 @@
|
||||
|
||||
#[derive(Default, Debug, Clone)]
|
||||
pub struct Vertex3D {
|
||||
position: [f32; 3]
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone)]
|
||||
pub struct ColoredVertex3D {
|
||||
position: [f32; 3],
|
||||
color : [u8; 4],
|
||||
}
|
Loading…
Reference in new issue