use glutin::ElementState::Pressed;
use glutin::Event::KeyboardInput;
use glutin::VirtualKeyCode;
-use libxm::XMContext;
-use sdl2::audio::{AudioCallback, AudioDevice, AudioSpecDesired};
-use std::fs::File;
-use std::io::Read;
+mod sound;
mod support;
#[derive(Copy, Clone)]
float zx2 = zx * zx;
float zy2 = zy * zy;
if (zx2 * zy2 > 4.0) {
- float index = 1.0 - float(iter) / float(maxiter);
- f_color = vec4(index, index * 0.5, index, index * 0.5);
+ float index = float(iter) / float(maxiter);
+ f_color = vec4(index, 0.1, 0.5 - index / 2, 0.8 - index);
return;
}
zy = zx * zy * 2.0 + c.y;
bounds: &Cube,
mandel_w: f32) {
let mut z0 = [mandel_w, 0f32];
- let zres = 50;
+ let zres = 30;
let zmin = bounds.zmin;
let zmax = bounds.zmax;
let zstep = (zmax - zmin) / zres as f32;
let mut zy = zmin;
- for _ in 0..zres {
+ // zres + 1 to reach the other face of the cube (fencepost error)
+ for _ in 0..(zres + 1) {
z0[1] = zy;
zy += zstep;
}
}
-struct XmCallback {
- xm: XMContext,
-}
-
-impl AudioCallback for XmCallback {
- type Channel = f32;
-
- fn callback(&mut self, out: &mut [f32]) {
- self.xm.generate_samples(out);
- }
-}
-
-struct SoundPlayer {
- _device: AudioDevice<XmCallback>,
-}
-
-fn play_xm(raw_xm: &[u8]) -> SoundPlayer {
- let sdl_context = sdl2::init().unwrap();
- let sdl_audio = sdl_context.audio().unwrap();
-
- let sample_rate = 48000u32;
- let desired_spec = AudioSpecDesired {
- freq: Some(sample_rate as i32),
- channels: Some(2u8),
- samples: None,
- };
- let device = sdl_audio.open_playback(None, &desired_spec, |actual_spec| {
- let xm = XMContext::new(&raw_xm, actual_spec.freq as u32).unwrap();
-
- XmCallback {
- xm: xm,
- }
- }).unwrap();
-
- device.resume();
-
- SoundPlayer {
- _device: device,
- }
-}
-
fn main() {
- let mut xm = Vec::new();
- File::open("flora.xm").unwrap().read_to_end(&mut xm).unwrap();
- let _sound_player = play_xm(&xm);
+ sound::start();
let display = glium::glutin::WindowBuilder::new()
//.with_dimensions(1024, 768)
xmax: 0.7,
ymin: -1.0,
ymax: 1.0,
- zmin: -1.2,
- zmax: 1.2,
+ zmin: -1.1,
+ zmax: 1.1,
};
// Vary the wow factor to slice the Mandelwow along its 4th dimension.
[ 0.0, 0.0, z_trans, 1.0f32]
];
- // 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.
+ // 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,