extern crate glfw;
use glfw::GlfwReceiver as Receiver;
use glfw::{Action, Key};
type WindowInstance = (glfw::PWindow, Receiver<(f64, glfw::WindowEvent)>);
type WindowVector = Vec<WindowInstance>;
fn add_window(glfw: &mut glfw::Glfw, window_vector: &mut WindowVector) {
let (mut window, events) = glfw
.create_window(300, 300, "Hello this is window", glfw::WindowMode::Windowed)
.expect("Failed to create GLFW window.");
window.set_key_polling(true);
window_vector.push((window, events));
}
fn handle_window_event(window: &mut glfw::Window, event: glfw::WindowEvent) {
match event {
glfw::WindowEvent::Key(Key::Escape, _, Action::Press, _) => window.set_should_close(true),
_ => {}
}
}
fn main() {
let mut glfw = glfw::init_no_callbacks().unwrap();
let mut windows = WindowVector::new();
add_window(&mut glfw, &mut windows);
add_window(&mut glfw, &mut windows);
while !windows.is_empty() {
glfw.wait_events();
for &mut (ref mut window, ref events) in &mut windows {
for (_, event) in glfw::flush_messages(events) {
handle_window_event(window, event);
}
}
windows.retain(|&(ref window, _)| !window.should_close());
}
}