rust/hwrunner/src/main.rs
author alfadur
Fri, 09 Nov 2018 20:15:29 +0300
changeset 14187 675aa499a70e
child 14188 3b83ec44e10b
permissions -rw-r--r--
add standalone engine runner
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14187
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
     1
use glutin::{
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
     2
    dpi::LogicalSize,
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
     3
    Event,
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
     4
    WindowEvent,
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
     5
    EventsLoop,
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
     6
    GlWindow,
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
     7
};
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
     8
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
     9
fn init(event_loop: &EventsLoop, size: LogicalSize) -> GlWindow {
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    10
    use glutin::{
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    11
        ContextBuilder,
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    12
        WindowBuilder
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    13
    };
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    14
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    15
    let window = WindowBuilder::new()
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    16
        .with_title("hwengine")
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    17
        .with_dimensions(size);
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    18
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    19
    let context = ContextBuilder::new();
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    20
    GlWindow::new(window, context, event_loop).unwrap()
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    21
}
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    22
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    23
fn main() {
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    24
    let mut event_loop = EventsLoop::new();
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    25
    let window = init(&event_loop, LogicalSize::new(1024.0, 768.0));
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    26
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    27
    let mut is_running = true;
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    28
    while is_running {
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    29
        event_loop.poll_events(|event| {
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    30
            match event {
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    31
                Event::WindowEvent { event, ..} => match event {
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    32
                    WindowEvent::CloseRequested => {
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    33
                        is_running = false;
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    34
                    },
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    35
                    _ => ()
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    36
                },
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    37
                _ => ()
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    38
            }
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    39
        })
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    40
    }
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    41
}