minimal sdl2 example
This commit is contained in:
parent
51b80af623
commit
57eb11a695
2 changed files with 43 additions and 6 deletions
|
@ -62,11 +62,7 @@
|
||||||
alsa-lib.dev
|
alsa-lib.dev
|
||||||
systemd.dev
|
systemd.dev
|
||||||
|
|
||||||
# X11 libs
|
SDL2
|
||||||
xorg.libX11
|
|
||||||
xorg.libXcursor
|
|
||||||
xorg.libXi
|
|
||||||
xorg.libXrandr
|
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
43
src/main.rs
43
src/main.rs
|
@ -1,3 +1,44 @@
|
||||||
fn main() {
|
extern crate sdl2;
|
||||||
|
|
||||||
|
use sdl2::pixels::Color;
|
||||||
|
use sdl2::event::Event;
|
||||||
|
use sdl2::keyboard::Keycode;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
pub fn main() {
|
||||||
println!("Hello, world!");
|
println!("Hello, world!");
|
||||||
|
let sdl_context = sdl2::init().unwrap();
|
||||||
|
let vide_subsystem = sdl_context.video().unwrap();
|
||||||
|
|
||||||
|
let window = vide_subsystem.window("fractals", 800, 600)
|
||||||
|
.position_centered()
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let mut canvas = window.into_canvas().build().unwrap();
|
||||||
|
|
||||||
|
canvas.set_draw_color(Color::RGB(0, 255, 255));
|
||||||
|
canvas.clear();
|
||||||
|
canvas.present();
|
||||||
|
|
||||||
|
let mut event_pump = sdl_context.event_pump().unwrap();
|
||||||
|
let mut i = 0;
|
||||||
|
|
||||||
|
'running: loop {
|
||||||
|
i = (i + 1) % 255;
|
||||||
|
canvas.set_draw_color(Color::RGB(i, 64, 255 - i));
|
||||||
|
canvas.clear();
|
||||||
|
for event in event_pump.poll_iter() {
|
||||||
|
match event {
|
||||||
|
Event::Quit { .. } |
|
||||||
|
Event::KeyDown { keycode: Some(Keycode::Escape), .. } => {
|
||||||
|
break 'running
|
||||||
|
},
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
canvas.present();
|
||||||
|
::std::thread::sleep(Duration::new(0, 1_000_000_000 / 60));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue