Crates.io | piston_window |
lib.rs | piston_window |
version | 0.132.0 |
source | src |
created_at | 2015-04-13 11:22:44.414213 |
updated_at | 2024-05-21 23:57:44.564431 |
description | The official Piston window wrapper for the Piston game engine |
homepage | https://github.com/pistondevelopers/piston_window |
repository | https://github.com/pistondevelopers/piston_window.git |
max_upload_size | |
id | 1860 |
size | 82,761 |
The official Piston convenience window wrapper for the Piston game engine
Notice! If this is your first time visiting Piston, start here.
Piston-Window is designed for only one purpose: Convenience.
.draw_2d
for drawing 2D, and .draw_3d
for drawing 3Dextern crate piston_window;
use piston_window::*;
fn main() {
let mut window: PistonWindow = WindowSettings::new("Hello Piston!", (640, 480))
.exit_on_esc(true)
.build()
.unwrap_or_else(|e| { panic!("Failed to build PistonWindow: {}", e) });
while let Some(e) = window.next() {
window.draw_2d(&e, |_c, g, _d| {
clear([0.5, 1.0, 0.5, 1.0], g);
});
}
}
PistonWindow
uses Glutin as window back-end by default,
but you can change to another back-end, for example SDL2 or GLFW by changing the type parameter:
let mut window: PistonWindow<Sdl2Window> = WindowSettings::new("Hello Piston!", [640, 480])
.exit_on_esc(true).build().unwrap();
PistonWindow
implements AdvancedWindow
, Window
and EventLoop
.
Nested game loops are supported, so you can have one inside another.
while let Some(e) = window.next() {
if let Some(button) = e.press_args() {
// Intro.
while let Some(e) = window.next() {
...
}
}
}
Ideas or feedback? Open up an issue here.