diff options
author | Tom Barrett <tom@tombarrett.xyz> | 2020-03-04 07:20:49 -0600 |
---|---|---|
committer | Tom Barrett <tom@tombarrett.xyz> | 2020-03-04 07:20:49 -0600 |
commit | c7d13e2721482772c12b44773777c5902f25848c (patch) | |
tree | ad87eaa9487c4336febe8ec07d39077e67897f58 /src | |
parent | 0c0b348971ee209679b571977115537daf9288cf (diff) |
removed surface from inits, now have vector of tessalations, added all the c84 colors
Diffstat (limited to 'src')
-rw-r--r-- | src/constants.rs | 17 | ||||
-rw-r--r-- | src/main.rs | 14 | ||||
-rw-r--r-- | src/n1ck.rs | 39 | ||||
-rw-r--r-- | src/tom.rs | 89 |
4 files changed, 92 insertions, 67 deletions
diff --git a/src/constants.rs b/src/constants.rs index 4f87ae4..cc26d4a 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -1,2 +1,19 @@ pub const WIDTH: u32 = 640; pub const HEIGHT: u32 = 480; + +pub const C64_BLACK: [u8; 3] = [0, 0, 0]; +pub const C64_WHITE: [u8; 3] = [255, 255, 255]; +pub const C64_RED: [u8; 3] = [136, 0, 0]; +pub const C64_CYAN: [u8; 3] = [170, 255, 238]; +pub const C64_VIOLET: [u8; 3] = [204, 68, 204]; +pub const C64_GREEN: [u8; 3] = [0, 204, 85]; +pub const C64_BLUE: [u8; 3] = [0, 0, 170]; +pub const C64_YELLOW: [u8; 3] = [238, 238, 119]; +pub const C64_ORANGE: [u8; 3] = [221, 136, 85]; +pub const C64_BROWN: [u8; 3] = [102, 68, 0]; +pub const C64_LIGHT_RED: [u8; 3] = [255, 119, 119]; +pub const C64_DARK_GREY: [u8; 3] = [51, 51, 51]; +pub const C64_GREY: [u8; 3] = [119, 119, 119]; +pub const C64_LIGHT_GREEN: [u8; 3] = [170, 255, 102]; +pub const C64_LIGHT_BLUE: [u8; 3] = [0, 136, 255]; +pub const C64_LIGHT_GREY: [u8; 3] = [187, 187, 187]; diff --git a/src/main.rs b/src/main.rs index 81b8585..546628f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -48,7 +48,7 @@ fn gen_viewports() -> Vec<Viewport> { } fn main() { - let surface = GlfwSurface::new( + let mut surface = GlfwSurface::new( WindowDim::Windowed(constants::WIDTH, constants::HEIGHT), "revision2020", WindowOpt::default(), @@ -64,8 +64,8 @@ fn main() { //let mut stream = audio::init(); //stream.play(); - let (mut tom, surface) = Tom::new(surface); - let (mut n1ck, mut surface) = N1ck::new(surface); + let mut tom = Tom::new(); + let mut n1ck = N1ck::new(); let viewports = gen_viewports(); @@ -90,13 +90,9 @@ fn main() { pipeline_state = pipeline_state.set_viewport(*viewport); pipeline_state = pipeline_state.enable_clear_color(false); - if i == 0 { + if i == 0 || i == 3 { surface = tom.draw(surface, &back_buffer, &program, &pipeline_state); - } else if i == 1 { - surface = n1ck.draw(surface, &back_buffer, &program, &pipeline_state); - } else if i == 2 { - surface = tom.draw(surface, &back_buffer, &program, &pipeline_state); - } else if i == 3 { + } else if i == 1 || i == 2 { surface = n1ck.draw(surface, &back_buffer, &program, &pipeline_state); } } diff --git a/src/n1ck.rs b/src/n1ck.rs index db77278..721e755 100644 --- a/src/n1ck.rs +++ b/src/n1ck.rs @@ -35,37 +35,34 @@ fn alter_vertices(vertices: &mut Vec<Vertex>) { } } +#[derive(Default)] pub struct N1ck { vertices: Vec<Vertex>, - tessalation: Tess, + tessalations: Vec<Tess>, } impl N1ck { - pub fn new<T: GraphicsContext>(mut surface: T) -> (N1ck, T) { + pub fn new() -> N1ck { let vertices = gen_vertices(); - let tessalation = TessBuilder::new(&mut surface) - .add_vertices(&vertices) - .set_mode(Mode::Triangle) - .build() - .unwrap(); + let tessalations = Vec::new(); - ( - N1ck { - vertices, - tessalation, - }, - surface, - ) + N1ck { + vertices, + tessalations, + } } pub fn update<T: GraphicsContext>(&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(); + self.tessalations.push( + TessBuilder::new(&mut surface) + .add_vertices(&self.vertices) + .set_mode(Mode::Triangle) + .build() + .unwrap(), + ); surface } @@ -83,7 +80,9 @@ impl N1ck { |_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(..)); + } }); }); }, @@ -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<Vertex> { +fn gen_rectangle(x1: f32, y1: f32, x2: f32, y2: f32, color: [u8; 3]) -> Vec<Vertex> { let mut vertices: Vec<Vertex> = 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<Vertex>) { - for vertex in vertices { - if vertex.color[0] < 255 { - vertex.color[0] += 1; - } - } +fn gen_border() -> Vec<Vec<Vertex>> { + let mut vertices: Vec<Vec<Vertex>> = 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<Vertex>, - tessalation: Tess, + vertices: Vec<Vec<Vertex>>, + tessalations: Vec<Tess>, } impl Tom { - pub fn new<T: GraphicsContext>(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<T: GraphicsContext>(&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(..)); + } }); }); }, |