From 74a4a35d5beec18524d51a6612558cbe1374303f Mon Sep 17 00:00:00 2001 From: Dane Johnson Date: Wed, 6 Apr 2022 17:32:55 -0500 Subject: [PATCH] External shaders --- src/flat.frag | 8 ++++++++ src/flat.vert | 11 +++++++++++ src/main.rs | 25 ++----------------------- 3 files changed, 21 insertions(+), 23 deletions(-) create mode 100644 src/flat.frag create mode 100644 src/flat.vert diff --git a/src/flat.frag b/src/flat.frag new file mode 100644 index 0000000..f789f10 --- /dev/null +++ b/src/flat.frag @@ -0,0 +1,8 @@ +#version 330 + +in vec3 DIFFUSE; +out vec4 color; + +void main() { + color = vec4(DIFFUSE, 1.0); +} diff --git a/src/flat.vert b/src/flat.vert new file mode 100644 index 0000000..d9dec66 --- /dev/null +++ b/src/flat.vert @@ -0,0 +1,11 @@ +#version 330 + +in vec2 position; +in vec3 color; + +out vec3 DIFFUSE; + +void main() { + gl_Position = vec4(position, 0.0, 1.0); + DIFFUSE = color; +} diff --git a/src/main.rs b/src/main.rs index caea7ba..9c9c50b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,29 +27,8 @@ fn main() { let vertex_buffer = glium::VertexBuffer::new(&display, &shape).unwrap(); let indices = glium::index::NoIndices(glium::index::PrimitiveType::TrianglesList); - let vertex_shader_src = r#" - #version 330 - - in vec2 position; - in vec3 color; - - out vec3 DIFFUSE; - - void main() { - gl_Position = vec4(position, 0.0, 1.0); - DIFFUSE = color; - } -"#; - let fragment_shader_src = r#" - #version 330 - - in vec3 DIFFUSE; - out vec4 color; - - void main() { - color = vec4(DIFFUSE, 1.0); - } -"#; + let vertex_shader_src = include_str!("flat.vert"); + let fragment_shader_src = include_str!("flat.frag"); let program = glium::Program::from_source(&display, vertex_shader_src, fragment_shader_src, None).unwrap(); events_loop.run(move |ev, _, control_flow| {