From c7d13e2721482772c12b44773777c5902f25848c Mon Sep 17 00:00:00 2001 From: Tom Barrett Date: Wed, 4 Mar 2020 07:20:49 -0600 Subject: removed surface from inits, now have vector of tessalations, added all the c84 colors --- src/tom.rs | 89 +++++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 51 insertions(+), 38 deletions(-) (limited to 'src/tom.rs') diff --git a/src/tom.rs b/src/tom.rs index dfdc846..b4e89f7 100644 --- a/src/tom.rs +++ b/src/tom.rs @@ -6,66 +6,77 @@ use luminance::shader::program::Program; use luminance::tess::{Mode, Tess, TessBuilder, TessSliceIndex}; use luminance::texture::Dim2; +use crate::constants; use crate::vertex::{Vertex, VertexPosition, VertexRGB, VertexSemantics}; -fn gen_vertices() -> Vec { +fn gen_rectangle(x1: f32, y1: f32, x2: f32, y2: f32, color: [u8; 3]) -> Vec { let mut vertices: Vec = Vec::new(); vertices.push(Vertex { - position: VertexPosition::new([-0.5, -0.5]), - color: VertexRGB::new([255, 0, 0]), + position: VertexPosition::new([x1, y1]), + color: VertexRGB::new(color), }); + vertices.push(Vertex { - position: VertexPosition::new([0.5, -0.5]), - color: VertexRGB::new([0, 255, 0]), + position: VertexPosition::new([x1, y2]), + color: VertexRGB::new(color), }); + + vertices.push(Vertex { + position: VertexPosition::new([x2, y2]), + color: VertexRGB::new(color), + }); + vertices.push(Vertex { - position: VertexPosition::new([0.0, 0.5]), - color: VertexRGB::new([0, 0, 255]), + position: VertexPosition::new([x2, y1]), + color: VertexRGB::new(color), }); vertices } -fn alter_vertices(vertices: &mut Vec) { - for vertex in vertices { - if vertex.color[0] < 255 { - vertex.color[0] += 1; - } - } +fn gen_border() -> Vec> { + let mut vertices: Vec> = Vec::new(); + + vertices.push(gen_rectangle(-1.0, -1.0, 1.0, -0.9, constants::C64_RED)); + + vertices.push(gen_rectangle(-1.0, -1.0, -0.9, 1.0, constants::C64_GREEN)); + + vertices.push(gen_rectangle(-1.0, 1.0, 1.0, 0.9, constants::C64_BLUE)); + + vertices.push(gen_rectangle(0.9, 1.0, 1.0, -1.0, constants::C64_VIOLET)); + + vertices } +#[derive(Default)] pub struct Tom { - vertices: Vec, - tessalation: Tess, + vertices: Vec>, + tessalations: Vec, } impl Tom { - pub fn new(mut surface: T) -> (Tom, T) { - let vertices = gen_vertices(); - let tessalation = TessBuilder::new(&mut surface) - .add_vertices(&vertices) - .set_mode(Mode::Triangle) - .build() - .unwrap(); - - ( - Tom { - vertices, - tessalation, - }, - surface, - ) + pub fn new() -> Tom { + let vertices = gen_border(); + let tessalations = Vec::new(); + + Tom { + vertices, + tessalations, + } } pub fn update(&mut self, mut surface: T) -> T { - alter_vertices(&mut self.vertices); - - self.tessalation = TessBuilder::new(&mut surface) - .add_vertices(&self.vertices) - .set_mode(Mode::Triangle) - .build() - .unwrap(); + self.tessalations.clear(); + for vertices in self.vertices.iter() { + self.tessalations.push( + TessBuilder::new(&mut surface) + .add_vertices(vertices) + .set_mode(Mode::TriangleFan) + .build() + .unwrap(), + ); + } surface } @@ -83,7 +94,9 @@ impl Tom { |_pipeline, mut shd_gate| { shd_gate.shade(&program, |_, mut rdr_gate| { rdr_gate.render(&RenderState::default(), |mut tess_gate| { - tess_gate.render(self.tessalation.slice(..)); + for tessalation in self.tessalations.iter() { + tess_gate.render(tessalation.slice(..)); + } }); }); }, -- cgit v1.2.3