#gfx #piston #piston-game-engine

piston_window

The official Piston window wrapper for the Piston game engine

132 breaking releases

Uses old Rust 2015

0.132.0 May 21, 2024
0.131.0 Nov 14, 2023
0.130.0 Sep 26, 2023
0.128.0 Feb 25, 2023
0.12.0 Jul 31, 2015

#696 in Game dev

Download history 732/week @ 2024-07-03 2493/week @ 2024-07-10 2969/week @ 2024-07-17 2632/week @ 2024-07-24 3177/week @ 2024-07-31 3837/week @ 2024-08-07 3057/week @ 2024-08-14 2668/week @ 2024-08-21 2955/week @ 2024-08-28 2769/week @ 2024-09-04 2824/week @ 2024-09-11 2708/week @ 2024-09-18 3029/week @ 2024-09-25 2038/week @ 2024-10-02 1177/week @ 2024-10-09 1617/week @ 2024-10-16

8,548 downloads per month
Used in fewer than 71 crates

MIT license

25KB
306 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

~5–15MB
~215K SLoC