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 = r#"
10 uniform mat4 perspective;
15 mat4 modelview = view * model;
16 gl_Position = perspective * modelview * vec4(position, 1.0);
20 let fragment_shader_src = r#"
26 color = vec4(1.0, 1.0, 1.0, 1.0);
30 return Program::from_source(display, vertex_shader_src, fragment_shader_src, None).unwrap();
33 pub fn draw<U>(display: &Display,
34 frame: &mut glium::Frame,
37 cube: &Cube) where U: glium::uniforms::Uniforms {
39 #[derive(Copy, Clone)]
40 struct Vertex { position: [f32; 3] }
41 implement_vertex!(Vertex, position);
44 Vertex { position: [cube.xmin, cube.ymin, cube.zmin] },
45 Vertex { position: [cube.xmax, cube.ymin, cube.zmin] },
46 Vertex { position: [cube.xmax, cube.ymax, cube.zmin] },
47 Vertex { position: [cube.xmin, cube.ymax, cube.zmin] },
48 Vertex { position: [cube.xmin, cube.ymin, cube.zmax] },
49 Vertex { position: [cube.xmax, cube.ymin, cube.zmax] },
50 Vertex { position: [cube.xmax, cube.ymax, cube.zmax] },
51 Vertex { position: [cube.xmin, cube.ymax, cube.zmax] },
53 let vb = glium::VertexBuffer::new(display, &cube).unwrap();
55 let params = glium::DrawParameters {
57 test: glium::draw_parameters::DepthTest::IfLess,
61 blend: glium::Blend::alpha_blending(),
65 let front_indices = IndexBuffer::new(display, PrimitiveType::LineLoop,
66 &[0, 1, 2, 3u16]).unwrap();
67 frame.draw(&vb, &front_indices, program, uniforms, ¶ms).unwrap();
69 let back_indices = IndexBuffer::new(display, PrimitiveType::LineLoop,
70 &[4, 5, 6, 7u16]).unwrap();
71 frame.draw(&vb, &back_indices, program, uniforms, ¶ms).unwrap();
73 let sides_indices = IndexBuffer::new(display, PrimitiveType::LinesList,
74 &[0, 4, 1, 5, 2, 6, 3, 7u16]).unwrap();
75 frame.draw(&vb, &sides_indices, program, uniforms, ¶ms).unwrap();