extern crate rand;
#[macro_use]
extern crate glium;
extern crate image;
use std::io::Cursor;
use glium::{glutin, Surface};
mod support;
fn main() {
let mut events_loop = glutin::EventsLoop::new();
let window = glutin::WindowBuilder::new();
let context = glutin::ContextBuilder::new().with_vsync(true);
let display = glium::Display::new(window, context, &events_loop).unwrap();
let image = image::load(Cursor::new(&include_bytes!("../tests/fixture/opengl.png")[..]),
image::PNG).unwrap().to_rgba();
let image_dimensions = image.dimensions();
let image = glium::texture::RawImage2d::from_raw_rgba_reversed(&image.into_raw(), image_dimensions);
let opengl_texture = glium::Texture2d::new(&display, image).unwrap();
let dest_texture = glium::Texture2d::empty_with_format(&display,
glium::texture::UncompressedFloatFormat::U8U8U8U8,
glium::texture::MipmapsOption::NoMipmap,
1024, 1024).unwrap();
dest_texture.as_surface().clear_color(0.0, 0.0, 0.0, 1.0);
support::start_loop(|| {
if rand::random::<f64>() <= 0.016666 {
let (left, bottom, dimensions): (f32, f32, f32) = rand::random();
let dest_rect = glium::BlitTarget {
left: (left * dest_texture.get_width() as f32) as u32,
bottom: (bottom * dest_texture.get_height().unwrap() as f32) as u32,
width: (dimensions * dest_texture.get_width() as f32) as i32,
height: (dimensions * dest_texture.get_height().unwrap() as f32) as i32,
};
opengl_texture.as_surface().blit_whole_color_to(&dest_texture.as_surface(), &dest_rect,
glium::uniforms::MagnifySamplerFilter::Linear);
}
let target = display.draw();
dest_texture.as_surface().fill(&target, glium::uniforms::MagnifySamplerFilter::Linear);
target.finish().unwrap();
let mut action = support::Action::Continue;
events_loop.poll_events(|event| {
match event {
glutin::Event::WindowEvent { event, .. } => match event {
glutin::WindowEvent::Closed => action = support::Action::Stop,
_ => (),
},
_ => (),
}
});
action
});
}