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,
36 uniform mat4 perspective;
45 mat4 modelview = view * model;
46 gl_Position = perspective * modelview * vec4(position, 1.0);
47 c = vec2(position.x, position.y);
54 precision highp float;
67 if (zx2 * zy2 > 4.0) {
68 float index = float(iter) / float(maxiter);
69 f_color = vec4(index, 0.1, 0.5 - index / 2, 0.8 - index);
72 zy = zx * zy * 2.0 + c.y;
76 f_color = vec4((sin(z.y) + 1.0) / 2,
85 fn mandel<U>(display: &glium::Display,
86 frame: &mut glium::Frame,
87 program: &glium::Program,
90 z: [f32; 2]) where U: glium::uniforms::Uniforms {
92 #[derive(Copy, Clone)]
97 implement_vertex!(Vertex, position, color);
99 let xmin = bounds.xmin;
100 let xmax = bounds.xmax;
101 let ymin = bounds.ymin;
102 let ymax = bounds.ymax;
104 let width = xmax - xmin;
105 let height = ymax - ymin;
108 let xstep = width / (xres as f32);
109 let ystep = height / (yres as f32);
110 let vb_size = (xres * 2 + 4) * yres;
111 let mut v : Vec<Vertex> = Vec::with_capacity(vb_size);
112 v.resize(vb_size, Vertex { position: [0.0, 0.0, -1.0], color: [0.0, 0.0, 0.0] });
113 let mut i: usize = 0;
118 let c = [0.0, 0.0, 1.0];
119 v[i] = Vertex { position: [vx, vy+ystep, vz], color: c }; i += 1;
120 v[i] = Vertex { position: [vx, vy, vz], color: c }; i += 1;
122 //let c = mand(vx, vy);
123 v[i] = Vertex { position: [vx+xstep, vy+ystep, vz], color: c }; i += 1;
124 v[i] = Vertex { position: [vx+xstep, vy, vz], color: c }; i += 1;
127 v[i] = Vertex { position: [vx, vy, vz], color: c }; i += 1;
128 v[i] = Vertex { position: [xmin, vy, vz], color: c }; i += 1;
132 //let vb = glium::VertexBuffer::empty_persistent(display, width*height*3).unwrap();
133 let vb = glium::VertexBuffer::new(display, &v).unwrap();
135 let indices = glium::index::NoIndices(PrimitiveType::TriangleStrip);
136 //let indices = glium::index::NoIndices(PrimitiveType::LineStrip);
137 //let indices = glium::IndexBuffer::new(display, PrimitiveType::TrianglesList,
138 // &[0u16, 1, 2]).unwrap();
140 let params = glium::DrawParameters {
141 depth: glium::Depth {
142 test: glium::draw_parameters::DepthTest::IfLess,
146 blend: glium::Blend::alpha_blending(),
150 frame.draw(&vb, &indices, program, uniforms, ¶ms).unwrap();
153 pub fn draw(display: &glium::Display,
154 mut frame: &mut glium::Frame,
155 program: &glium::Program,
156 model: [[f32; 4]; 4],
157 camera: &support::camera::CameraState,
160 let mut z0 = [mandel_w, 0f32];
162 let zmin = bounds.zmin;
163 let zmax = bounds.zmax;
164 let zstep = (zmax - zmin) / zres as f32;
166 // zres + 1 to reach the other face of the cube (fencepost error)
167 for _ in 0..(zres + 1) {
171 let uniforms = uniform! {
174 view: camera.get_view(),
175 perspective: camera.get_perspective(),
178 mandel(&display, &mut frame, &program, &uniforms, bounds, z0);