extern crate glfw;
use glfw::{Action, Key};
use std::sync::mpsc::Receiver;
type WindowInstance = (glfw::Window, Receiver<(f64,glfw::WindowEvent)>);
type WindowVector = Vec<WindowInstance>;
fn add_window(glfw: &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(glfw::FAIL_ON_ERRORS).unwrap();
let mut windows = WindowVector::new();
add_window(&glfw, &mut windows);
add_window(&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());
}
}