From cdab0086ec6eae662a9c40503f302f391141fbc0 Mon Sep 17 00:00:00 2001 From: Tom Barrett Date: Fri, 24 Jan 2020 01:56:40 -0600 Subject: example --- .gitignore | 2 + Cargo.lock | 228 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 10 +++ src/fs.glsl | 7 ++ src/main.rs | 98 ++++++++++++++++++++++++++ src/vs.glsl | 9 +++ 6 files changed, 354 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 src/fs.glsl create mode 100644 src/main.rs create mode 100644 src/vs.glsl diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..53eaa21 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/target +**/*.rs.bk diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..17e4504 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,228 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "bitflags" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "cc" +version = "1.0.50" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "cmake" +version = "0.1.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cc 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "gl" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "gl_generator 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "gl_generator" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "khronos_api 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "xml-rs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "glfw" +version = "0.34.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "glfw-sys 3.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "objc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", + "raw-window-handle 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "glfw-sys" +version = "3.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cmake 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "khronos_api" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "libc" +version = "0.2.66" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "log" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "luminance" +version = "0.38.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "gl 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "luminance-derive" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "luminance-glfw" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "gl 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", + "glfw 0.34.0 (registry+https://github.com/rust-lang/crates.io-index)", + "luminance 0.38.0 (registry+https://github.com/rust-lang/crates.io-index)", + "luminance-windowing 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "luminance-windowing" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "luminance 0.38.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "malloc_buf" +version = "0.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "objc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "malloc_buf 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "proc-macro2" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "quote" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "raw-window-handle" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "semver" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "semver-parser" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "syn" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "unicode-xid" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "working-title" +version = "0.1.0" +dependencies = [ + "luminance 0.38.0 (registry+https://github.com/rust-lang/crates.io-index)", + "luminance-derive 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "luminance-glfw 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "xml-rs" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[metadata] +"checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +"checksum cc 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)" = "95e28fa049fda1c330bcf9d723be7663a899c4679724b34c81e9f5a326aab8cd" +"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" +"checksum cmake 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "81fb25b677f8bf1eb325017cb6bb8452f87969db0fedb4f757b297bee78a7c62" +"checksum gl 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a94edab108827d67608095e269cf862e60d920f144a5026d3dbcfd8b877fb404" +"checksum gl_generator 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1a95dfc23a2b4a9a2f5ab41d194f8bfda3cabec42af4e39f08c339eb2a0c124d" +"checksum glfw 0.34.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4270c54da6c6035d29daf646ede04d2f10e95ad082a0e5f9f6031f6559a86dcc" +"checksum glfw-sys 3.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0b567b13b593ec58ea912b2658ee6230ffe20a069fa5b771800acc69bb3a157e" +"checksum khronos_api 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2db585e1d738fc771bf08a151420d3ed193d9d895a36df7f6f8a9456b911ddc" +"checksum libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)" = "d515b1f41455adea1313a4a2ac8a8a477634fbae63cc6100e3aebb207ce61558" +"checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" +"checksum luminance 0.38.0 (registry+https://github.com/rust-lang/crates.io-index)" = "20a5ff8bdb29331980a9686ae18da865b1314aa5aa0da372417b85e90ba7af7c" +"checksum luminance-derive 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "265977f33e48d911ff387df65836e2b8df7a8453b74739da191ad89c5359e2d9" +"checksum luminance-glfw 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "72f1022037ad7fa1693e3571fb83fea51443b6a0a81a1efc7bcaba835e5fd44d" +"checksum luminance-windowing 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c796dd7f672459aaf0afdaad3de3134735ea3b6467cf5762556dcc9f4ae4e01a" +"checksum malloc_buf 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb" +"checksum objc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1" +"checksum proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3acb317c6ff86a4e579dfa00fc5e6cca91ecbb4e7eb2df0468805b674eb88548" +"checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe" +"checksum raw-window-handle 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0a441a7a6c80ad6473bd4b74ec1c9a4c951794285bf941c2126f607c72e48211" +"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" +"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" +"checksum syn 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)" = "af6f3550d8dff9ef7dc34d384ac6f107e5d31c8f57d9f28e0081503f547ac8f5" +"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" +"checksum xml-rs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "541b12c998c5b56aa2b4e6f18f03664eef9a4fd0a246a55594efae6cc2d964b5" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..8ad6de8 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "working-title" +version = "0.1.0" +authors = ["Tom Barrett "] +edition = "2018" + +[dependencies] +luminance = "0.38" +luminance-derive = "0.5.2" +luminance-glfw = "0.12" diff --git a/src/fs.glsl b/src/fs.glsl new file mode 100644 index 0000000..d2dd6bb --- /dev/null +++ b/src/fs.glsl @@ -0,0 +1,7 @@ +in vec3 v_color; + +out vec3 frag_color; + +void main() { + frag_color = v_color; +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..bf607eb --- /dev/null +++ b/src/main.rs @@ -0,0 +1,98 @@ +use luminance::context::GraphicsContext; +use luminance::pipeline::PipelineState; +use luminance::render_state::RenderState; +use luminance::shader::program::Program; +use luminance::tess::{Mode, TessBuilder, TessSliceIndex}; +use luminance_derive::{Semantics, Vertex}; +use luminance_glfw::{GlfwSurface, Surface, WindowDim, WindowEvent, WindowOpt}; + +#[derive(Vertex)] +#[vertex(sem = "VertexSemantics")] +pub struct Vertex { + position: VertexPosition, + #[vertex(normalized = "true")] + color: VertexRGB, +} + +#[derive(Copy, Clone, Debug, Semantics)] +pub enum VertexSemantics { + #[sem(name = "position", repr = "[f32; 2]", wrapper = "VertexPosition")] + Position, + #[sem(name = "color", repr = "[u8; 3]", wrapper = "VertexRGB")] + Color, +} + +fn gen_vertices() -> Vec { + let mut vertices: Vec = 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) { + for vertex in vertices { + vertex.position[0] += 0.01; + if vertex.color[1] < 255 { + vertex.color[1] += 1; + } + } +} + +fn main() { + let mut surface = + GlfwSurface::new(WindowDim::Windowed(500, 500), "art", WindowOpt::default()).unwrap(); + //GlfwSurface::new(WindowDim::Fullscreen, "art", WindowOpt::default()).unwrap(); + + let program: Program = + Program::from_strings(None, include_str!("vs.glsl"), None, include_str!("fs.glsl")) + .unwrap() + .ignore_warnings(); + + let mut vertices = gen_vertices(); + + let mut run = true; + + while run { + for event in surface.poll_events() { + if let WindowEvent::Close = event { + run = false; + } + } + + let back_buffer = surface.back_buffer().unwrap(); + + alter_vertices(&mut vertices); + + let triangle = TessBuilder::new(&mut surface) + .add_vertices(&vertices) + .set_mode(Mode::Triangle) + .build() + .unwrap(); + + surface.pipeline_builder().pipeline( + &back_buffer, + &PipelineState::default(), + |_pipeline, mut shd_gate| { + shd_gate.shade(&program, |_, mut rdr_gate| { + rdr_gate.render(&RenderState::default(), |mut tess_gate| { + tess_gate.render(triangle.slice(..)); + }); + }); + }, + ); + + surface.swap_buffers(); + } +} diff --git a/src/vs.glsl b/src/vs.glsl new file mode 100644 index 0000000..97f4a8f --- /dev/null +++ b/src/vs.glsl @@ -0,0 +1,9 @@ +in vec2 position; +in vec3 color; + +out vec3 v_color; + +void main() { + v_color = color; + gl_Position = vec4(position, 0., 1.); +} -- cgit v1.2.3