-
-
Notifications
You must be signed in to change notification settings - Fork 477
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
81 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#![cfg(any(target_os = "windows"))] | ||
#![cfg(target_os = "windows")] | ||
|
||
mod make_current_guard; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#![cfg(target_os = "android")] | ||
|
||
mod support; | ||
|
||
use glutin::event::{Event, WindowEvent}; | ||
use glutin::event_loop::{ControlFlow, EventLoop}; | ||
use glutin::window::WindowBuilder; | ||
|
||
#[cfg_attr(target_os = "android", ndk_glue::main(backtrace = "on"))] | ||
fn main() { | ||
println!("App started"); | ||
let el = EventLoop::new(); | ||
|
||
// On Android a window is only available (ndk_glue::native_window() returns Some, | ||
// to create an EGL context on) after Resumed is received, and disappears when | ||
// Suspended is received. | ||
|
||
let mut state = None; | ||
|
||
el.run(move |event, el, control_flow| { | ||
*control_flow = ControlFlow::Wait; | ||
|
||
println!("{:?}", &event); | ||
|
||
match event { | ||
Event::Resumed => { | ||
println!("Android window available"); | ||
let wb = WindowBuilder::new().with_title("Hello world!"); | ||
let windowed_context = | ||
glutin::ContextBuilder::new().build_windowed(wb, el).unwrap(); | ||
|
||
let windowed_context = unsafe { windowed_context.make_current().unwrap() }; | ||
|
||
let gl = support::load(windowed_context.context()); | ||
|
||
state = Some((windowed_context, gl)); | ||
} | ||
Event::Suspended => { | ||
println!("Android window removed"); | ||
// Destroy the GL context before ndk-glue releases the window back to the system | ||
state = None; | ||
} | ||
Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => { | ||
*control_flow = ControlFlow::Exit | ||
} | ||
Event::WindowEvent { event: WindowEvent::Resized(size), .. } => { | ||
if let Some((windowed_context, _)) = &state { | ||
windowed_context.resize(size); | ||
windowed_context.window().request_redraw(); | ||
} | ||
} | ||
Event::RedrawRequested(_) => { | ||
if let Some((windowed_context, gl)) = &state { | ||
gl.draw_frame([1.0, 0.5, 0.7, 1.0]); | ||
windowed_context.swap_buffers().unwrap(); | ||
} | ||
} | ||
_ => {} | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#![cfg(any(target_os = "windows"))] | ||
#![cfg(target_os = "windows")] | ||
|
||
/// WGL bindings | ||
pub mod wgl { | ||
|