5 use glium::index::PrimitiveType;
11 fn mand(cx: f32, cy: f32) -> [f32; 3] {
13 let mut iter = maxiter;
20 return [iter as f32 / maxiter as f32, 1.0, 1.0];
22 zy = zx * zy * 2.0 + cy;
31 pub fn program(display: &glium::Display) -> glium::Program {
32 return program!(display,
34 vertex: include_str!("mandelwow.vert"),
35 fragment: include_str!("mandelwow.frag"),
39 fn mandel<U>(display: &glium::Display,
40 frame: &mut glium::Frame,
41 program: &glium::Program,
44 z: [f32; 2]) where U: glium::uniforms::Uniforms {
46 #[derive(Copy, Clone)]
51 implement_vertex!(Vertex, position, color);
53 let xmin = bounds.xmin;
54 let xmax = bounds.xmax;
55 let ymin = bounds.ymin;
56 let ymax = bounds.ymax;
58 let width = xmax - xmin;
59 let height = ymax - ymin;
62 let xstep = width / (xres as f32);
63 let ystep = height / (yres as f32);
64 let vb_size = (xres * 2 + 4) * yres;
65 let mut v : Vec<Vertex> = Vec::with_capacity(vb_size);
66 v.resize(vb_size, Vertex { position: [0.0, 0.0, -1.0], color: [0.0, 0.0, 0.0] });
72 let c = [0.0, 0.0, 1.0];
73 v[i] = Vertex { position: [vx, vy+ystep, vz], color: c }; i += 1;
74 v[i] = Vertex { position: [vx, vy, vz], color: c }; i += 1;
76 //let c = mand(vx, vy);
77 v[i] = Vertex { position: [vx+xstep, vy+ystep, vz], color: c }; i += 1;
78 v[i] = Vertex { position: [vx+xstep, vy, vz], color: c }; i += 1;
81 v[i] = Vertex { position: [vx, vy, vz], color: c }; i += 1;
82 v[i] = Vertex { position: [xmin, vy, vz], color: c }; i += 1;
86 //let vb = glium::VertexBuffer::empty_persistent(display, width*height*3).unwrap();
87 let vb = glium::VertexBuffer::new(display, &v).unwrap();
89 let indices = glium::index::NoIndices(PrimitiveType::TriangleStrip);
90 //let indices = glium::index::NoIndices(PrimitiveType::LineStrip);
91 //let indices = glium::IndexBuffer::new(display, PrimitiveType::TrianglesList,
92 // &[0u16, 1, 2]).unwrap();
94 let params = glium::DrawParameters {
96 test: glium::draw_parameters::DepthTest::IfLess,
100 blend: glium::Blend::alpha_blending(),
104 frame.draw(&vb, &indices, program, uniforms, ¶ms).unwrap();
107 pub fn draw(display: &glium::Display,
108 mut frame: &mut glium::Frame,
109 program: &glium::Program,
110 model: [[f32; 4]; 4],
111 camera: &support::camera::CameraState,
114 let mut z0 = [mandel_w, 0f32];
116 let zmin = bounds.zmin;
117 let zmax = bounds.zmax;
118 let zstep = (zmax - zmin) / zres as f32;
120 // zres + 1 to reach the other face of the cube (fencepost error)
121 for _ in 0..(zres + 1) {
125 let uniforms = uniform! {
128 view: camera.get_view(),
129 perspective: camera.get_perspective(),
132 mandel(&display, &mut frame, &program, &uniforms, bounds, z0);