From 76fc76631cf155123b127f5bc576d2922c536ebc Mon Sep 17 00:00:00 2001 From: Bernie Innocenti Date: Mon, 3 Apr 2017 01:03:14 -0400 Subject: [PATCH] Add bounding box toggling with the B key. --- mandelwow.rs | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/mandelwow.rs b/mandelwow.rs index fc6bcf7..8feb2b9 100644 --- a/mandelwow.rs +++ b/mandelwow.rs @@ -7,8 +7,8 @@ extern crate glutin; use glium::DisplayBuild; use glium::Surface; -use glium::index::PrimitiveType; use glium::index::IndexBuffer; +use glium::index::PrimitiveType; mod support; @@ -149,7 +149,15 @@ fn bounding_box(display: &glium::Display, ]; let vb = glium::VertexBuffer::new(display, &cube).unwrap(); - let params = Default::default(); + let params = glium::DrawParameters { + depth: glium::Depth { + test: glium::draw_parameters::DepthTest::IfLess, + write: true, + .. Default::default() + }, + blend: glium::Blend::alpha_blending(), + .. Default::default() + }; let front_indices = IndexBuffer::new(display, PrimitiveType::LineLoop, &[0, 1, 2, 3u16]).unwrap(); @@ -268,9 +276,13 @@ fn main() { .build_glium() .unwrap(); + let program = mandelwow_program(&display); + let bounding_box_program = solid_fill_program(&display); + let mut camera = support::camera::CameraState::new(); let mut t: f32 = 0.0; let mut pause = false; + let mut bounding_box_enabled = true; support::start_loop(|| { camera.update(); @@ -309,18 +321,19 @@ fn main() { [ 0.0, 0.0, z_trans, 1.0f32] ]; - let program = mandelwow_program(&display); - let bounding_box_program = solid_fill_program(&display); + // Draw the bounding box before the fractal, when the Z-buffer is still clear, so the lines + // behind the semi-translucent areas will be drawn. + if bounding_box_enabled { + let uniforms = uniform! { + model: model, + view: camera.get_view(), + perspective: camera.get_perspective(), + }; + bounding_box(&display, &mut frame, &bounding_box_program, &uniforms, &bounds); + } mandelwow(&display, &mut frame, &program, model, &camera, &bounds, wow); - let uniforms = uniform! { - model: model, - view: camera.get_view(), - perspective: camera.get_perspective(), - }; - bounding_box(&display, &mut frame, &bounding_box_program, &uniforms, &bounds); - for ev in display.poll_events() { match ev { glium::glutin::Event::Closed => { @@ -336,6 +349,9 @@ fn main() { glutin::Event::KeyboardInput(glutin::ElementState::Pressed, _, Some(glutin::VirtualKeyCode::P)) => { pause ^= true; }, + glutin::Event::KeyboardInput(glutin::ElementState::Pressed, _, Some(glutin::VirtualKeyCode::B)) => { + bounding_box_enabled ^= true; + }, ev => camera.process_input(&ev), } } -- 2.25.1