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 pub fn draw<U>(display: &Display,
13 frame: &mut glium::Frame,
16 cube: &Cube) where U: glium::uniforms::Uniforms {
18 #[derive(Copy, Clone)]
19 struct Vertex { position: [f32; 3] }
20 implement_vertex!(Vertex, position);
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] },
32 let vb = glium::VertexBuffer::new(display, &cube).unwrap();
34 let params = glium::DrawParameters {
36 test: glium::draw_parameters::DepthTest::IfLess,
40 blend: glium::Blend::alpha_blending(),
44 let front_indices = IndexBuffer::new(display, PrimitiveType::LineLoop,
45 &[0, 1, 2, 3u16]).unwrap();
46 frame.draw(&vb, &front_indices, program, uniforms, ¶ms).unwrap();
48 let back_indices = IndexBuffer::new(display, PrimitiveType::LineLoop,
49 &[4, 5, 6, 7u16]).unwrap();
50 frame.draw(&vb, &back_indices, program, uniforms, ¶ms).unwrap();
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, ¶ms).unwrap();