11 use glium::{DisplayBuild, Surface};
12 use glutin::ElementState::Pressed;
13 use glutin::Event::KeyboardInput;
14 use glutin::VirtualKeyCode;
23 let _soundplayer = sound::start();
25 let display = glium::glutin::WindowBuilder::new()
26 //.with_dimensions(1024, 768)
27 .with_fullscreen(glutin::get_primary_monitor())
28 .with_depth_buffer(24)
30 .with_title(format!("MandelWow"))
34 let mandelwow_program = mandelwow::program(&display);
35 let bounding_box_program = bounding_box::solid_fill_program(&display);
37 let mut camera = support::camera::CameraState::new();
39 let mut pause = false;
40 let mut bounding_box_enabled = true;
41 let mut fullscreen = true;
43 // These are the bounds of the 3D Mandelwow section which we render in 3-space.
53 support::start_loop(|| {
61 // Vary the wow factor to slice the Mandelwow along its 4th dimension.
64 let wsize = wmax - wmin;
65 let wow = (((t * 0.7).sin() + 1.0) / 2.0) * wsize + wmin;
67 //println!("t={} w={:?} camera={:?}", t, w, camera.get_pos());
69 let mut frame = display.draw();
70 frame.clear_color_and_depth((0.0, 0.0, 0.0, 1.0), 1.0);
72 let z_trans = -2.0; // Send the model back a little bit so it fits the screen.
74 [ t.cos(), t.sin(), 0.0, 0.0],
75 [-t.sin(), t.cos(), 0.0, 0.0],
76 [ 0.0, 0.0, 1.0, 0.0],
77 [ 0.0, 0.0, z_trans, 1.0f32]
80 // Draw the bounding box before the fractal, when the Z-buffer is still clear,
81 // so the lines behind the semi-translucent areas will be drawn.
82 if bounding_box_enabled {
83 let uniforms = uniform! {
85 view: camera.get_view(),
86 perspective: camera.get_perspective(),
88 bounding_box::draw(&display, &mut frame, &bounding_box_program, &uniforms, &bounds);
91 mandelwow::draw(&display, &mut frame, &mandelwow_program, model, &camera, &bounds, wow);
92 frame.finish().unwrap();
94 for ev in display.poll_events() {
96 glium::glutin::Event::Closed |
97 KeyboardInput(Pressed, _, Some(VirtualKeyCode::Escape)) |
98 KeyboardInput(Pressed, _, Some(VirtualKeyCode::Q)) => {
99 return support::Action::Stop
101 KeyboardInput(Pressed, _, Some(VirtualKeyCode::B)) => {
102 bounding_box_enabled ^= true;
104 KeyboardInput(Pressed, _, Some(VirtualKeyCode::F)) => {
107 glutin::WindowBuilder::new()
108 .with_fullscreen(glutin::get_primary_monitor())
109 .rebuild_glium(&display).unwrap();
111 glutin::WindowBuilder::new()
112 .rebuild_glium(&display).unwrap();
115 KeyboardInput(Pressed, _, Some(VirtualKeyCode::P)) => {
118 KeyboardInput(Pressed, _, Some(VirtualKeyCode::PageUp)) => {
121 KeyboardInput(Pressed, _, Some(VirtualKeyCode::PageDown)) => {
124 ev => camera.process_input(&ev),
128 support::Action::Continue