5 use glium::index::PrimitiveType;
6 use glium::{Display, Program, Surface};
10 fn mand(cx: f32, cy: f32) -> [f32; 3] {
12 let mut iter = maxiter;
19 return [iter as f32 / maxiter as f32, 1.0, 1.0];
21 zy = zx * zy * 2.0 + cy;
30 pub fn program(display: &Display) -> Program {
33 include_str!("shaders/mandelwow.vert"),
34 include_str!("shaders/mandelwow.frag"), None)
38 fn mandel<U>(display: &Display,
39 frame: &mut glium::Frame,
43 z: [f32; 2]) where U: glium::uniforms::Uniforms {
45 #[derive(Copy, Clone)]
50 implement_vertex!(Vertex, position, color);
52 let xmin = bounds.xmin;
53 let xmax = bounds.xmax;
54 let ymin = bounds.ymin;
55 let ymax = bounds.ymax;
57 let width = xmax - xmin;
58 let height = ymax - ymin;
61 let xstep = width / (xres as f32);
62 let ystep = height / (yres as f32);
63 let vb_size = (xres * 2 + 4) * yres;
64 let mut v : Vec<Vertex> = Vec::with_capacity(vb_size);
65 v.resize(vb_size, Vertex { position: [0.0, 0.0, -1.0], color: [0.0, 0.0, 0.0] });
71 let c = [0.0, 0.0, 1.0];
72 v[i] = Vertex { position: [vx, vy+ystep, vz], color: c }; i += 1;
73 v[i] = Vertex { position: [vx, vy, vz], color: c }; i += 1;
75 //let c = mand(vx, vy);
76 v[i] = Vertex { position: [vx+xstep, vy+ystep, vz], color: c }; i += 1;
77 v[i] = Vertex { position: [vx+xstep, vy, vz], color: c }; i += 1;
80 v[i] = Vertex { position: [vx, vy, vz], color: c }; i += 1;
81 v[i] = Vertex { position: [xmin, vy, vz], color: c }; i += 1;
85 //let vb = glium::VertexBuffer::empty_persistent(display, width*height*3).unwrap();
86 let vb = glium::VertexBuffer::new(display, &v).unwrap();
88 let indices = glium::index::NoIndices(PrimitiveType::TriangleStrip);
89 //let indices = glium::index::NoIndices(PrimitiveType::LineStrip);
90 //let indices = glium::IndexBuffer::new(display, PrimitiveType::TrianglesList,
91 // &[0u16, 1, 2]).unwrap();
93 let params = glium::DrawParameters {
95 test: glium::draw_parameters::DepthTest::IfLess,
99 blend: glium::Blend::alpha_blending(),
103 frame.draw(&vb, &indices, program, uniforms, ¶ms).unwrap();
106 pub fn draw(display: &Display,
107 mut frame: &mut glium::Frame,
109 model: [[f32; 4]; 4],
110 camera: &support::camera::CameraState,
113 let mut z0 = [mandel_w, 0f32];
115 let zmin = bounds.zmin;
116 let zmax = bounds.zmax;
117 let zstep = (zmax - zmin) / zres as f32;
119 // zres + 1 to reach the other face of the cube (fencepost error)
120 for _ in 0..(zres + 1) {
124 let uniforms = uniform! {
127 view: camera.get_view(),
128 perspective: camera.get_perspective(),
131 mandel(display, &mut frame, program, &uniforms, bounds, z0);