3 use glium::{Display, Program, Surface, implement_vertex};
4 use glium::index::{IndexBuffer, PrimitiveType};
7 pub fn solid_fill_program(display: &Display) -> Program {
8 let vertex_shader_src = include_str!("shaders/solid.vert");
9 let fragment_shader_src = include_str!("shaders/solid.frag");
10 Program::from_source(display, vertex_shader_src, fragment_shader_src, None).unwrap()
13 #[derive(Copy, Clone)]
14 struct Vertex { position: [f32; 3] }
15 implement_vertex!(Vertex, position);
17 pub struct BoundingBox {
18 vertexes: glium::VertexBuffer<Vertex>,
20 indices: IndexBuffer<u16>,
24 pub fn new(display: &Display, c: &Cube, program: Rc<Program>) -> BoundingBox {
26 Vertex { position: [c.xmin, c.ymin, c.zmin] },
27 Vertex { position: [c.xmax, c.ymin, c.zmin] },
28 Vertex { position: [c.xmax, c.ymax, c.zmin] },
29 Vertex { position: [c.xmin, c.ymax, c.zmin] },
30 Vertex { position: [c.xmin, c.ymin, c.zmax] },
31 Vertex { position: [c.xmax, c.ymin, c.zmax] },
32 Vertex { position: [c.xmax, c.ymax, c.zmax] },
33 Vertex { position: [c.xmin, c.ymax, c.zmax] },
36 const INDICES: &[u16] = &[0, 1, 1, 2, 2, 3, 3, 0, // front
37 4, 5, 5, 6, 6, 7, 7, 4, // back
38 0, 4, 1, 5, 2, 6, 3, 7]; // sides
41 vertexes: glium::VertexBuffer::new(display, &vertex_data).unwrap(),
43 indices: IndexBuffer::new(display, PrimitiveType::LinesList, INDICES).unwrap(),
47 pub fn draw<U>(&self, frame: &mut glium::Frame,
48 uniforms: &U) where U: glium::uniforms::Uniforms {
49 let params = glium::DrawParameters {
51 test: glium::draw_parameters::DepthTest::IfLess,
55 blend: glium::Blend::alpha_blending(),
58 frame.draw(&self.vertexes, &self.indices, &self.program, uniforms, ¶ms).unwrap();