#window #piston

piston_window

The official Piston window wrapper for the Piston game engine

128 breaking releases

Uses old Rust 2015

0.128.0 Feb 25, 2023
0.127.0 Nov 18, 2022
0.126.0 Nov 16, 2022
0.123.0 Feb 23, 2022
0.12.0 Jul 31, 2015

#107 in Games

Download history 2897/week @ 2022-11-27 3777/week @ 2022-12-04 4484/week @ 2022-12-11 4335/week @ 2022-12-18 3083/week @ 2022-12-25 2003/week @ 2023-01-01 3593/week @ 2023-01-08 1990/week @ 2023-01-15 4666/week @ 2023-01-22 5154/week @ 2023-01-29 3932/week @ 2023-02-05 2495/week @ 2023-02-12 5466/week @ 2023-02-19 1948/week @ 2023-02-26 5454/week @ 2023-03-05 2264/week @ 2023-03-12

15,590 downloads per month
Used in fewer than 63 crates

MIT license

22KB
299 lines

piston_window Build Status Crates.io Crates.io

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.

Documentation

  • Reexports everything you need to write 2D interactive applications
  • .draw_2d for drawing 2D, and .draw_3d for drawing 3D
  • Uses Gfx to work with 3D libraries in the Piston ecosystem
extern 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.

Dependency graph

Dependencies

Dependencies

~15–22MB
~311K SLoC