#[macro_use] extern crate glium; use glium::Surface; #[path = "../book/tuto-07-teapot.rs"] mod teapot; fn main() { let event_loop = glium::winit::event_loop::EventLoop::builder() .build() .expect("event loop building"); let (window, display) = glium::backend::glutin::SimpleWindowBuilder::new() .with_title("Glium tutorial #7") .build(&event_loop); let positions = glium::VertexBuffer::new(&display, &teapot::VERTICES).unwrap(); let normals = glium::VertexBuffer::new(&display, &teapot::NORMALS).unwrap(); let indices = glium::IndexBuffer::new(&display, glium::index::PrimitiveType::TrianglesList, &teapot::INDICES).unwrap(); let vertex_shader_src = r#" #version 140 in vec3 position; in vec3 normal; uniform mat4 matrix; void main() { gl_Position = matrix * vec4(position, 1.0); } "#; let fragment_shader_src = r#" #version 140 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(); #[allow(deprecated)] event_loop.run(move |ev, window_target| { match ev { glium::winit::event::Event::WindowEvent { event, .. } => match event { glium::winit::event::WindowEvent::CloseRequested => { window_target.exit(); }, // We now need to render everyting in response to a RedrawRequested event due to the animation glium::winit::event::WindowEvent::RedrawRequested => { let mut target = display.draw(); target.clear_color(0.0, 0.0, 1.0, 1.0); let matrix = [ [0.01, 0.0, 0.0, 0.0], [0.0, 0.01, 0.0, 0.0], [0.0, 0.0, 0.01, 0.0], [0.0, 0.0, 0.0, 1.0f32] ]; target.draw((&positions, &normals), &indices, &program, &uniform! { matrix: matrix }, &Default::default()).unwrap(); target.finish().unwrap(); }, // Because glium doesn't know about windows we need to resize the display // when the window's size has changed. glium::winit::event::WindowEvent::Resized(window_size) => { display.resize(window_size.into()); }, _ => (), }, // By requesting a redraw in response to a AboutToWait event we get continuous rendering. // For applications that only change due to user input you could remove this handler. glium::winit::event::Event::AboutToWait => { window.request_redraw(); }, _ => (), } }) .unwrap(); }