Skip to content
The official Piston convenience window wrapper for the Piston game engine
Rust
Branch: master
Clone or download
Latest commit a1b01f5 Aug 5, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples Add device parameter to `draw_2d` May 23, 2019
scripts Enable travis and docs Jun 6, 2015
src Published 0.100.0 Jul 8, 2019
.gitignore First commit Apr 13, 2015
.travis.yml Test on beta compiler release Dec 22, 2016
Cargo.png Added dependency graph Jun 6, 2015
Cargo.toml Published 0.103.0 Aug 5, 2019
LICENSE Initial commit Apr 13, 2015
README.md Make notice bold Jul 12, 2017

README.md

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| {
            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

You can’t perform that action at this time.