Implement mouse panning and streamline keyboard movement.
[mandelwow.git] / bounding_box.rs
1 use cube::Cube;
2 use glium;
3 use glium::{Display, Program, Surface};
4 use glium::index::{IndexBuffer, PrimitiveType};
5
6 pub fn solid_fill_program(display: &Display) -> Program {
7     let vertex_shader_src = include_str!("solid.vert");
8     let fragment_shader_src = include_str!("solid.frag");
9     return Program::from_source(display, vertex_shader_src, fragment_shader_src, None).unwrap();
10 }
11
12 pub fn draw<U>(display: &Display,
13                frame: &mut glium::Frame,
14                program: &Program,
15                uniforms: &U,
16                cube: &Cube) where U: glium::uniforms::Uniforms {
17
18     #[derive(Copy, Clone)]
19     struct Vertex { position: [f32; 3] }
20     implement_vertex!(Vertex, position);
21
22     let cube = [
23         Vertex { position: [cube.xmin, cube.ymin, cube.zmin] },
24         Vertex { position: [cube.xmax, cube.ymin, cube.zmin] },
25         Vertex { position: [cube.xmax, cube.ymax, cube.zmin] },
26         Vertex { position: [cube.xmin, cube.ymax, cube.zmin] },
27         Vertex { position: [cube.xmin, cube.ymin, cube.zmax] },
28         Vertex { position: [cube.xmax, cube.ymin, cube.zmax] },
29         Vertex { position: [cube.xmax, cube.ymax, cube.zmax] },
30         Vertex { position: [cube.xmin, cube.ymax, cube.zmax] },
31     ];
32     let vb = glium::VertexBuffer::new(display, &cube).unwrap();
33
34     let params = glium::DrawParameters {
35         depth: glium::Depth {
36             test: glium::draw_parameters::DepthTest::IfLess,
37             write: true,
38             ..Default::default()
39         },
40         blend: glium::Blend::alpha_blending(),
41         ..Default::default()
42     };
43
44     let front_indices = IndexBuffer::new(display, PrimitiveType::LineLoop,
45                                          &[0, 1, 2, 3u16]).unwrap();
46     frame.draw(&vb, &front_indices, program, uniforms, &params).unwrap();
47
48     let back_indices = IndexBuffer::new(display, PrimitiveType::LineLoop,
49                                         &[4, 5, 6, 7u16]).unwrap();
50     frame.draw(&vb, &back_indices, program, uniforms, &params).unwrap();
51
52     let sides_indices = IndexBuffer::new(display, PrimitiveType::LinesList,
53                                          &[0, 4, 1, 5, 2, 6, 3, 7u16]).unwrap();
54     frame.draw(&vb, &sides_indices, program, uniforms, &params).unwrap();
55 }