Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use glutin::event::{Event, WindowEvent};
- use glutin::event_loop::{ControlFlow, EventLoop};
- use glutin::window::{WindowBuilder};
- use glutin::{Context, ContextBuilder, PossiblyCurrent, WindowedContext};
- pub struct Window {
- window_context: WindowedContext<PossiblyCurrent>,
- event_loop: EventLoop<()>
- }
- impl Window {
- pub fn new() -> Self {
- let event_loop = EventLoop::new();
- let wb = WindowBuilder::new()
- .with_title("OpenGL Example")
- .with_resizable(true);
- let window_context = ContextBuilder::new()
- .build_windowed(wb, &event_loop)
- .expect("Could not create windowed context!");
- let window_context = unsafe {
- window_context.make_current()
- .expect("Could not front the current context")
- };
- Window {
- window_context,
- event_loop
- }
- }
- pub fn context(&self) -> &Context<PossiblyCurrent> {
- self.window_context.context()
- }
- pub fn run_with_draw(&self) {
- self.event_loop.run(move |event, _, control_flow| {
- *control_flow = ControlFlow::Wait;
- match event {
- Event::LoopDestroyed => return,
- Event::WindowEvent { ref event, .. } => match event {
- WindowEvent::Resized(logical_size) => {
- let dpi_factor = self.window_context.window()
- .hidpi_factor();
- self.window_context
- .resize(logical_size.to_physical(dpi_factor));
- }
- WindowEvent::RedrawRequested => {
- // Draw
- }
- WindowEvent::CloseRequested => {
- *control_flow = ControlFlow::Exit
- }
- _ => (),
- },
- _ => (),
- }
- });
- }
- }
- $ cargo build
- error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements
- --> src/window.rs:38:29
- |
- 38 | self.event_loop.run(move |event, _, control_flow| {
- | _____________________________^
- 39 | | *control_flow = ControlFlow::Wait;
- 40 | |
- 41 | | match event {
- ... |
- 60 | | }
- 61 | | });
- | |_________^
- |
- note: first, the lifetime cannot outlive the anonymous lifetime #1 defined on the method body at 37:5...
- --> src/window.rs:37:5
- |
- 37 | / pub fn run_with_draw(&self) {
- 38 | | self.event_loop.run(move |event, _, control_flow| {
- 39 | | *control_flow = ControlFlow::Wait;
- 40 | |
- ... |
- 61 | | });
- 62 | | }
- | |_____^
- = note: ...so that the types are compatible:
- expected &window::Window
- found &window::Window
- = note: but, the lifetime must be valid for the static lifetime...
- note: ...so that the type `[closure@src/window.rs:38:29: 61:10 self:&window::Window]` will meet its required lifetime bounds
- --> src/window.rs:38:25
- |
- 38 | self.event_loop.run(move |event, _, control_flow| {
- | ^^^
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement