examples: insert sdl2_demo
Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
This commit is contained in:
@@ -34,6 +34,7 @@ maud = { version = "~0.22.1" }
|
|||||||
#orbtk = { git = "https://github.com/redox-os/orbtk.git", branch = "develop" }
|
#orbtk = { git = "https://github.com/redox-os/orbtk.git", branch = "develop" }
|
||||||
orbtk = { path = "../../../orbtk" }
|
orbtk = { path = "../../../orbtk" }
|
||||||
serde = { version = "~1.0", features = ["derive"] }
|
serde = { version = "~1.0", features = ["derive"] }
|
||||||
|
sdl2 = { version = "~0.34" }
|
||||||
substring = { version = "~1" }
|
substring = { version = "~1" }
|
||||||
#tokio = { version = "~0.2", features = ["macros", "rt-threaded", "stream", "time"] }
|
#tokio = { version = "~0.2", features = ["macros", "rt-threaded", "stream", "time"] }
|
||||||
tracing = { version = "~0.1" }
|
tracing = { version = "~0.1" }
|
||||||
|
|||||||
45
crates/advotracker_client/examples/sdl2_demo.rs
Normal file
45
crates/advotracker_client/examples/sdl2_demo.rs
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
extern crate sdl2;
|
||||||
|
|
||||||
|
use sdl2::event::Event;
|
||||||
|
use sdl2::keyboard::Keycode;
|
||||||
|
use sdl2::pixels::Color;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
pub fn main() -> Result<(), String> {
|
||||||
|
let sdl_context = sdl2::init()?;
|
||||||
|
let video_subsystem = sdl_context.video()?;
|
||||||
|
|
||||||
|
let window = video_subsystem
|
||||||
|
.window("rust-sdl2 demo: Video", 800, 600)
|
||||||
|
.position_centered()
|
||||||
|
.opengl()
|
||||||
|
.build()
|
||||||
|
.map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
|
let mut canvas = window.into_canvas().build().map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
|
canvas.set_draw_color(Color::RGB(255, 0, 0));
|
||||||
|
canvas.clear();
|
||||||
|
canvas.present();
|
||||||
|
let mut event_pump = sdl_context.event_pump()?;
|
||||||
|
|
||||||
|
'running: loop {
|
||||||
|
for event in event_pump.poll_iter() {
|
||||||
|
match event {
|
||||||
|
Event::Quit { .. }
|
||||||
|
| Event::KeyDown {
|
||||||
|
keycode: Some(Keycode::Escape),
|
||||||
|
..
|
||||||
|
} => break 'running,
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
canvas.clear();
|
||||||
|
canvas.present();
|
||||||
|
::std::thread::sleep(Duration::new(0, 1_000_000_000u32 / 30));
|
||||||
|
// The rest of the game loop goes here...
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user