This commit is contained in:
parent
23bef7585d
commit
04c79728e9
3 changed files with 2117 additions and 0 deletions
58
src/main.rs
Normal file
58
src/main.rs
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
use glium::winit::event::{Event, WindowEvent};
|
||||
use glium::Surface;
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
struct Vertex {
|
||||
position: [f32; 2],
|
||||
}
|
||||
implement_vertex!(Vertex, position);
|
||||
|
||||
#[macro_use]
|
||||
extern crate glium;
|
||||
|
||||
fn main() {
|
||||
let event_loop = glium::winit::event_loop::EventLoopBuilder::new().build().expect("event loop building");
|
||||
let (_window, display) = glium::backend::glutin::SimpleWindowBuilder::new().build(&event_loop);
|
||||
|
||||
let vertex1 = Vertex { position: [ -0.5, -0.5 ] };
|
||||
let vertex2 = Vertex { position: [ 0.0, 0.5 ] };
|
||||
let vertex3 = Vertex { position: [ 0.5, -0.25 ] };
|
||||
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#"
|
||||
in vec2 position;
|
||||
|
||||
void main() {
|
||||
gl_Position = vec4(position, 0.0, 1.0);
|
||||
}
|
||||
"#;
|
||||
|
||||
let fragment_shader_src = r#"
|
||||
out vec4 color;
|
||||
|
||||
void main() {
|
||||
color = vec4(1.0, 0.0, 0.0, 1.0);
|
||||
}
|
||||
"#;
|
||||
|
||||
let program = glium::Program::from_source(&display, vertex_shader_src, fragment_shader_src, None).unwrap();
|
||||
|
||||
let mut frame = display.draw();
|
||||
frame.clear_color(0.0, 0.0, 0.0, 1.0);
|
||||
frame.draw(&vertex_buffer, &indices, &program, &glium::uniforms::EmptyUniforms,
|
||||
&Default::default()).unwrap();
|
||||
frame.finish().unwrap();
|
||||
|
||||
let _ = event_loop.run(move |event, window_target| {
|
||||
match event {
|
||||
Event::WindowEvent { event, .. } => match event {
|
||||
WindowEvent::CloseRequested => window_target.exit(),
|
||||
_ => (),
|
||||
},
|
||||
_ => (),
|
||||
};
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue