summaryrefslogtreecommitdiff
path: root/src/n1ck.rs
diff options
context:
space:
mode:
authorTom Barrett <tom@tombarrett.xyz>2020-03-04 01:26:52 -0600
committerTom Barrett <tom@tombarrett.xyz>2020-03-04 01:26:52 -0600
commitaf5e8f365478f62bc5108217317e70a6ee1accf4 (patch)
treeecb72e11f3dded73eca3e46c50442008e4290c3f /src/n1ck.rs
parente79499cd864dc64017316ef4512991df68837576 (diff)
workable viewport structure
Diffstat (limited to 'src/n1ck.rs')
-rw-r--r--src/n1ck.rs94
1 files changed, 94 insertions, 0 deletions
diff --git a/src/n1ck.rs b/src/n1ck.rs
new file mode 100644
index 0000000..db77278
--- /dev/null
+++ b/src/n1ck.rs
@@ -0,0 +1,94 @@
+use luminance::context::GraphicsContext;
+use luminance::framebuffer::Framebuffer;
+use luminance::pipeline::PipelineState;
+use luminance::render_state::RenderState;
+use luminance::shader::program::Program;
+use luminance::tess::{Mode, Tess, TessBuilder, TessSliceIndex};
+use luminance::texture::Dim2;
+
+use crate::vertex::{Vertex, VertexPosition, VertexRGB, VertexSemantics};
+
+fn gen_vertices() -> 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]),
+ });
+ vertices.push(Vertex {
+ position: VertexPosition::new([0.5, -0.5]),
+ color: VertexRGB::new([0, 255, 0]),
+ });
+ vertices.push(Vertex {
+ position: VertexPosition::new([0.0, 0.5]),
+ color: VertexRGB::new([0, 0, 255]),
+ });
+
+ vertices
+}
+
+fn alter_vertices(vertices: &mut Vec<Vertex>) {
+ for vertex in vertices {
+ if vertex.color[1] < 255 {
+ vertex.color[1] += 1;
+ }
+ }
+}
+
+pub struct N1ck {
+ vertices: Vec<Vertex>,
+ tessalation: Tess,
+}
+
+impl N1ck {
+ pub fn new<T: GraphicsContext>(mut surface: T) -> (N1ck, T) {
+ let vertices = gen_vertices();
+ let tessalation = TessBuilder::new(&mut surface)
+ .add_vertices(&vertices)
+ .set_mode(Mode::Triangle)
+ .build()
+ .unwrap();
+
+ (
+ N1ck {
+ vertices,
+ tessalation,
+ },
+ surface,
+ )
+ }
+
+ 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();
+
+ surface
+ }
+
+ pub fn draw<T: GraphicsContext>(
+ &self,
+ mut surface: T,
+ back_buffer: &Framebuffer<Dim2, (), ()>,
+ program: &Program<VertexSemantics, (), ()>,
+ pipeline_state: &PipelineState,
+ ) -> T {
+ surface.pipeline_builder().pipeline(
+ &back_buffer,
+ &pipeline_state,
+ |_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(..));
+ });
+ });
+ },
+ );
+
+ surface
+ }
+}