3 use glium::{Display, Program, Surface};
4 use glium::index::{IndexBuffer, PrimitiveType};
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();
12 #[derive(Copy, Clone)]
13 struct Vertex { position: [f32; 3] }
14 implement_vertex!(Vertex, position);
16 pub struct BoundingBox<'a> {
17 vertexes: glium::VertexBuffer<Vertex>,
19 indices: IndexBuffer<u16>,
22 impl<'a> BoundingBox<'a> {
23 pub fn new(display: &Display, c: &Cube, program: &'a Program) -> BoundingBox<'a> {
25 Vertex { position: [c.xmin, c.ymin, c.zmin] },
26 Vertex { position: [c.xmax, c.ymin, c.zmin] },
27 Vertex { position: [c.xmax, c.ymax, c.zmin] },
28 Vertex { position: [c.xmin, c.ymax, c.zmin] },
29 Vertex { position: [c.xmin, c.ymin, c.zmax] },
30 Vertex { position: [c.xmax, c.ymin, c.zmax] },
31 Vertex { position: [c.xmax, c.ymax, c.zmax] },
32 Vertex { position: [c.xmin, c.ymax, c.zmax] },
35 const INDICES: &[u16] = &[0, 1, 1, 2, 2, 3, 3, 0, // front
36 4, 5, 5, 6, 6, 7, 7, 4, // back
37 0, 4, 1, 5, 2, 6, 3, 7]; // sides
40 vertexes: glium::VertexBuffer::new(display, &vertex_data).unwrap(),
42 indices: IndexBuffer::new(display, PrimitiveType::LinesList, INDICES).unwrap(),
46 pub fn draw<U>(&self, frame: &mut glium::Frame,
47 uniforms: &U) where U: glium::uniforms::Uniforms {
48 let params = glium::DrawParameters {
50 test: glium::draw_parameters::DepthTest::IfLess,
54 blend: glium::Blend::alpha_blending(),
57 frame.draw(&self.vertexes, &self.indices, &self.program, uniforms, ¶ms).unwrap();