Draw some pretty colors
This commit is contained in:
parent
9a33becab8
commit
311eb0227c
47
src/main.rs
47
src/main.rs
@ -1,5 +1,14 @@
|
|||||||
|
#[macro_use]
|
||||||
extern crate glium;
|
extern crate glium;
|
||||||
|
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
struct Vertex {
|
||||||
|
position: [f32; 2],
|
||||||
|
color: [f32; 3],
|
||||||
|
}
|
||||||
|
|
||||||
|
implement_vertex!(Vertex, position, color);
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
use glium::{glutin, Surface};
|
use glium::{glutin, Surface};
|
||||||
|
|
||||||
@ -10,12 +19,48 @@ fn main() {
|
|||||||
|
|
||||||
let display = glium::Display::new(wb, cb, &events_loop).unwrap();
|
let display = glium::Display::new(wb, cb, &events_loop).unwrap();
|
||||||
|
|
||||||
|
let vertex1 = Vertex { position: [-0.5, -0.5], color: [1.0, 0.0, 0.0] };
|
||||||
|
let vertex2 = Vertex { position: [ 0.0, 0.5], color: [0.0, 1.0, 0.0] };
|
||||||
|
let vertex3 = Vertex { position: [ 0.5, -0.25], color: [0.0, 0.0, 1.0]};
|
||||||
|
let shape = vec![vertex1, vertex2, vertex3];
|
||||||
|
|
||||||
|
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 program = glium::Program::from_source(&display, vertex_shader_src, fragment_shader_src, None).unwrap();
|
||||||
|
|
||||||
events_loop.run(move |ev, _, control_flow| {
|
events_loop.run(move |ev, _, control_flow| {
|
||||||
|
|
||||||
let mut target = display.draw();
|
let mut target = display.draw();
|
||||||
target.clear_color(0.0, 0.0, 1.0, 1.0);
|
target.clear_color(0.0, 0.0, 0.0, 1.0);
|
||||||
|
target.draw(&vertex_buffer, &indices, &program, &glium::uniforms::EmptyUniforms,
|
||||||
|
&Default::default()).unwrap();
|
||||||
target.finish().unwrap();
|
target.finish().unwrap();
|
||||||
|
|
||||||
|
|
||||||
let next_frame_time = std::time::Instant::now() +
|
let next_frame_time = std::time::Instant::now() +
|
||||||
std::time::Duration::from_nanos(16_666_667);
|
std::time::Duration::from_nanos(16_666_667);
|
||||||
*control_flow = glutin::event_loop::ControlFlow::WaitUntil(next_frame_time);
|
*control_flow = glutin::event_loop::ControlFlow::WaitUntil(next_frame_time);
|
||||||
|
Loading…
Reference in New Issue
Block a user