A modular game engine written in Rust



Build Status Crates.io Crates.io

A modular game engine written in Rust

Maintainers of Piston core libraries: @bvssvni

Dive into the world of Piston

Start new project with Piston

You should know how to build "hello world" with Rust, see http://www.rust-lang.org/.

Drawing a red rectangle

Add piston_window to your Cargo.toml, for example:

piston_window = "*"

In "src/main.rs", type the following code:

extern crate piston_window;

use piston_window::*;

fn main() {
    let mut window: PistonWindow =
        WindowSettings::new("Hello Piston!", [640, 480])
    while let Some(event) = window.next() {
        window.draw_2d(&event, |context, graphics, _device| {
            clear([1.0; 4], graphics);
            rectangle([1.0, 0.0, 0.0, 1.0], // red
                      [0.0, 0.0, 100.0, 100.0],

Use cargo run to start the application. It should clear the screen in white color and draw a red rectangle.



The Piston project is a large collaboration among many developers. There are libraries for 2D, 3D, event programming, AI, image processing etc. By sharing the maintenance, we get more time to build new stuff.

Piston is as much a community project as it is a collection of libraries. Writing and maintaining code is expensive, and by sharing this cost we reach our goals faster. We believe that seeking personal goals and ambitions, while helping each other, results in higher quality.

  • Our main goal is to free up time for maintainers, and the people involved
  • ... such that we can create new amazing stuff and reach our personal goals
  • ... by making more people use Rust for game development and become engaged in open source

In addition, we do research or plan to in the following areas:

Dependency graph


  • Couldn't find any pixel format that matched the criterias.

    Couldn't find any pixel format that matched the criterias.

    I have been able to run my own programs using piston for a while, but since a few days I suddenly get this error.

    When trying to run cargo run --bin hello_world from the piston_examples:

    thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: "Couldn\'t find any pixel format that matches the criterias."', /checkout/src/libcore/result.rs:860:4
    stack backtrace:
       0: std::sys::imp::backtrace::tracing::imp::unwind_backtrace
                 at /checkout/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
       1: std::sys_common::backtrace::_print
                 at /checkout/src/libstd/sys_common/backtrace.rs:71
       2: std::panicking::default_hook::{{closure}}
                 at /checkout/src/libstd/sys_common/backtrace.rs:60
                 at /checkout/src/libstd/panicking.rs:380
       3: std::panicking::default_hook
                 at /checkout/src/libstd/panicking.rs:396
       4: std::panicking::rust_panic_with_hook
                 at /checkout/src/libstd/panicking.rs:611
       5: std::panicking::begin_panic_new
                 at /checkout/src/libstd/panicking.rs:553
       6: std::panicking::begin_panic_fmt
                 at /checkout/src/libstd/panicking.rs:521
       7: rust_begin_unwind
                 at /checkout/src/libstd/panicking.rs:497
       8: core::panicking::panic_fmt
                 at /checkout/src/libcore/panicking.rs:92
       9: core::result::unwrap_failed
                 at /checkout/src/libcore/macros.rs:41
      10: <core::result::Result<T, E>>::unwrap
                 at /checkout/src/libcore/result.rs:738
      11: hello_world::main
                 at src/hello_world.rs:7
      12: __rust_maybe_catch_panic
                 at /checkout/src/libpanic_unwind/lib.rs:98
      13: std::rt::lang_start
                 at /checkout/src/libstd/panicking.rs:458
                 at /checkout/src/libstd/panic.rs:361
                 at /checkout/src/libstd/rt.rs:59
      14: main
      15: __libc_start_main
      16: _start


    Antergos, based on Arch Linux $ uname -r: 4.12.12-1-ARCH $ cargo --version: cargo 0.21.0 (5b4b8b2ae 2017-08-12) $ rustc --version: rustc 1.20.0 (f3d6973f4 2017-08-27) $ rustup --version: rustup 1.6.0

    glxinfo recently updated packages, most notably:

    • upgraded mesa (17.1.8-1 -> 17.1.8-2)
    • upgraded gtk3 (3.22.19-2 -> 3.22.20-1)
    • upgraded linux (4.12.10-1 -> 4.12.12-1)

    Update 4: All intermediate versions of mesa (17.1.8-1, 17.1.8-2, 17.2.0-2, 17.2.0-3, 17.2.1-3, 17.2.2-1) have this same problem.

    Let me know if you need more information 😄

    Update: Seems to be the case for all OpenGL versions. Rebooting didn't work either. Update 2: Also happens on a clean Debian 9 (kernel 4.9.0-3-amd64) build in VirtualBox 5.1.26 Update 3: Also happens on Rust 1.19.0, and Rust 1.18.0 and earlier don't compile

    opened by Cxarli 45
  • Keep `Game` trait or use iterators only?

    Keep `Game` trait or use iterators only?

    One problem is after redesigning the iterator to take advantage of the stack environment, they will no longer be isomorphic. You can't take a game written with the Game trait and translate it to using iterators by just copying and pasting code.

    opened by bvssvni 43
  • pixel format not found

    pixel format not found

    Trying to the run the example in the README.md with the red square, I compile successfully ( I ran cargo build twice just in case, the first one was successful, the 2nd one was a failure to build glutin because the system couldnt not find a file) but encounter a panic "Couldn't find any pixel format that matches the criterias.". I'm probably missing a dependency, just not sure what.

    opened by 5ynatra 26
  • game proposal

    game proposal

    Some of you might have read the issue #670 about collaborating on a new open source game. I have been in touch with @bvssvni to let him know about my current plan to develop a game.

    My motivation to create such a game is to expose as many people as possible to the "open source" way of doing things . Not only to developers who already understand the benefits but also for people of other trade such as designers, musicians, voice actors, movie directors, … I believe a game is the ideal medium to converge all our the efforts to create something meaningful, something we can be proud of.

    Hopefully this project can help generate momentum for the Piston framework and promote the creation of a new set of libraries that in turn could be used in other projects. It can be a testing ground for new features and test the limits of their implementation.

    Now let's talk about the game. It is currently called project R where the "R" stands for Renaissance. It is a reference to the cultural movement following the "dark ages". Project R doesn't take place during that historical period but I hope we can achieve a renaissance 2.0 of our own.

    The goal of this project is to create a highly customizable multiplayer game.

    The main game: As a new player, you are asked to select a zone where you would like to start the adventure from. Every zone is culturally and architecturally different but it is possible as you evolve to travel to remote regions. You also receive some piece of land where you can build your home but Since you just started the adventure you don't have any gold to buy raw material and make your home. You are now required to go to the mountain area and collect some raw material. Because you have selected a specific zone, the bricks, tiles, and other structural element will look similar to the existing buildings.

    Now that you have built your home, you can still go to the mountain area to collect raw material but this time to sell it to the local construction store. The resell price is subject to supply and demand. This is one of the many ways you can earn extra gold.

    Gold can buy food and useful items that can be stored in your home for later use. Without food your character can't survive long enough to explore this world and join new games.

    Some items are free some other require gold. These items will be crafted by the community so they can set their own price or requirements. This is where the community can get creative.

    You can customize your character look and personality. You can buy clothing and accessories to express yourself. Not all customization are available for purchase. For example, your daily food intake and energy expenditure will define your stamina and overall shape.

    That's nice and all but it's pretty boring to collect items for no other reason than storing them. This is where you get to join a game .

    Secondary game: The first game will be a 2D plan fighting game where characters are rendered in 3D but the "hitbox/hurtbox" collision is calculated on 2D objects. A fighter is a good first game because it doesn't require the creation of complex puzzle or intricate story. With a minimal set of tools it is possible to play for hours. You have to understand your options and their consequences , make decisions in real time and also try to guess what your opponent is thinking by observing his/her movements and habits. Also for those who have heard about the project mugen, you can see what is possible when the community is given control over content creation.

    You can join the fighting game by enrolling in a school or dojo . Every zone has a specific fighting style and mastery of one or more of the elements that make up the game universe. You learn from your master the basics of your fighting style and train with players that are about the same level as you. You don't get to use the power of the elements just yet but you can already start leveling up your basic attacks and can also compete for the rookie title.

    Every week a competition is taking place and you have to fight a member of a competing style. You know in advance who you will be fighting so you can prepare and level up accordingly. All the fights are recorded and can be watched live by players who decided not to join the competitive mode or are just waiting for their fight to start. The next day is the main event where masters fight each other. The "master tournament" outcome will influence the game story and this is where we get to watch the next "episode"...

    That's pretty much the idea behind this project I have skipped some of the features/ideas but I think for now it should be enough to get the conversation started. I hope some of you are still interested and if so I will be answering questions on this thread.

    thanks for reading

    opened by advanced 26
  • image not rendered in

    image not rendered in "image" example

    Executing "image" produces a blank window.

    Linux 3.14.5-1-ARCH #1 SMP PREEMPT Sun Jun 1 07:38:50 CEST 2014 i686 GNU/Linux Intel Corporation Mobile 945GM/GMS, 943/940GML Express Integrated Graphics Controller (rev 03) OpenGL version string: 2.1 Mesa 10.1.4

    opened by fortpolio 24
  • piston lacks an explanation of the game loop

    piston lacks an explanation of the game loop

    How do we go from (c++, from http://gameprogrammingpatterns.com/game-loop.html)

    double previous = getCurrentTime();
    double lag = 0.0;
    while (true)
      double current = getCurrentTime();
      double elapsed = current - previous;
      previous = current;
      lag += elapsed;
      while (lag >= MS_PER_UPDATE)
        lag -= MS_PER_UPDATE;

    to using piston in our editor?

    opened by KingOfThePirates 20
  • Rebrand from

    Rebrand from "game engine" to "game framework"

    From the comment http://www.reddit.com/r/rust_gamedev/comments/2jiep0/the_new_look_of_wwwpistonrs/clcpyc9

    The way you describe Piston sounds like it has more in common with game frameworks than game engines; if that's the case some rebranding might be in order to prevent future confusion.

    opened by bvssvni 19
  • Piston Freezes During Compilation with Cargo Build

    Piston Freezes During Compilation with Cargo Build

    I'm attempting to compile my project via cargo build, but compilation freezes when compiling piston. Eventually it exits out with the following error:

    vagrant@vagrant-ubuntu-trusty-32:/vagrant$ cargo build
           Fresh image v0.0.0 (https://github.com/PistonDevelopers/rust-image)
           Fresh codegen v0.0.1 (https://github.com/AngryLawyer/rust-sdl2)
           Fresh graphics v0.0.0 (https://github.com/PistonDevelopers/rust-graphics)
       Compiling piston v0.0.0 (https://github.com/PistonDevelopers/piston)
           Fresh gl v0.0.1 (https://github.com/bjz/gl-rs)
           Fresh sdl2 v0.0.1 (https://github.com/AngryLawyer/rust-sdl2)
           Fresh opengl_graphics v0.0.0 (https://github.com/PistonDevelopers/opengl_graphics)
    Could not execute process `rustc src/lib.rs --crate-type lib --out-dir /vagrant/piston/target -L /vagrant/piston/target -L /vagrant/piston/target/deps` (status=9)

    Attempting to clone and build piston individually with cargo build results in the following error:

    vagrant@vagrant-ubuntu-trusty-32:/vagrant/piston$ cargo build
       Compiling piston v0.0.0 (file:/vagrant/piston)
    Could not execute process `rustc src/lib.rs --crate-type lib --out-dir /vagrant/piston/target -L /vagrant/piston/target -L /vagrant/piston/target/deps` (status=9)

    Attempting to build piston with the above command results in compilation freezing and no progress being made (it doesn't error or crash, just waits for the command to exit):

    vagrant@vagrant-ubuntu-trusty-32:/vagrant/piston$ rustc src/lib.rs --crate-type lib --out-dir /vagrant/piston/target -L /vagrant/piston/target -L /vagrant/piston/target/deps

    Any ideas?

    rustc -v: rustc 0.11.0-pre
    uname -a: Linux vagrant-ubuntu-trusty-32 3.13.0-29-generic #53-Ubuntu SMP Wed Jun 4 21:02:19 UTC 2014 i686 i686 i686 GNU/Linux
    opened by indiv0 19
  • Mouse enter/leave window events

    Mouse enter/leave window events

    AFAICT, we don't currently provide events for when the mouse enters/leaves the window (a separate event from focus gained/lost), which would help situations like https://github.com/PistonDevelopers/drag_controller/issues/20.

    Obviously, since this would be a pretty widespread breaking change, it'd be a good idea to bikeshed the design first. Perhaps add one or two new variants to input::Motion, since it concerns movement of the mouse cursor:

    pub enum Motion {
        // Existing variants omitted for brevity.
        /// The mouse has entered the window area.
        /// The mouse has left the window area.

    Or, it could be added as a single variant to input::Input, in parallel with Focus. I'm having difficulty coming up with a short variant name that clearly describes a mouse enter/leave event as a boolean. This was the best I could do:

    pub enum Input {
        // Other variants omitted
        /// Window gained or lost focus.
        /// Mouse cursor entered or left the window area.
    enhancement draft discussion 
    opened by abonander 18
  • Start an

    Start an "official" window back-end using Gfx and Glutin

    Gfx got some abstractions now that require integration between window and graphics. We could add a library gfx_window to glue this to wrapped piston window abstractions, or we could start a piston_window that uses Glutin directly.

    The argument is as following: If you want to use Gfx, which you need to use many 3D Piston libraries, then why would you want to use SDL2 or GLFW when Piston does the event abstraction, and Glutin provides a cross platform interface?

    opened by bvssvni 18
  • Major rethink to require multi-threads

    Major rethink to require multi-threads

    The idea is to execute render, update and input logic on a second/multiple threads while using the main thread to poll events and synchronize with the GPU.

    Major motivation is to create more room for library design that depend on a set of conventions, where the accessibility to certain resources are taken as granted. For example 1) window 2) device 3) sound.

    At the moment we struggle with the borrow checker because it forces us to pass around objects representing these resources, and all structures need to mutate their internal state to keep them around. It makes it impossible to use closures safely that specify a subroutine of some significant game logic, because the closure captures the objects that represent the resources. This prevents other parts from using those resources, even if they don't use them at the same time.

    One issue is that on some platforms, both rendering and event loop needs to happen on the main thread. This puts an upper limit of the accuracy of user input. If we use a second thread for updates and render logic, then the main thread will get better accuracy and can time stamp the events.

    Creating textures on demand without access to the device is simply not possible with Gfx's design. We could have channels for creation of different textures, such as glyph caching for Conrod. This could be implemented on library level such that whenever you depend on glyph caching, it is assumed that a channel is set up for that resource.

    The new asset_store makes it possible to load assets asynchronously, so this kind of thinking is not that far away from what we are currently doing. It might be that with the current design, we try to do too much on the same thread and is punished by the borrow checker for it.

    We might get rid of some of the boilerplate code, and some people here got ideas about "setups" that combine certain library. Perhaps it is time to brainstorm how we can improve the overall ergonomics and try to come up with some conventions that are efficient but easy to scale.

    opened by bvssvni 17
  • Noticable update event slow down, when laptop is disconnected from power

    Noticable update event slow down, when laptop is disconnected from power


    I noticed today when I disconnected my development laptop from power, game updates in my, very simple, Tetris clone slow down noticeably.

    To confirm the issue is not with my game code, I tested this on the piston getting started tutorial code and see the same slowdown occurs there. Attached a GIF of what I am seeing. You can clearly see the slowdown when the laptop is disconnected from power, and then speeds up when reconnected shortly after.

    Update Slowdown

    This seems like it shouldn't be normal behavior, right?

    opened by BeldrothTheGold 3
  • making audiogames (for blind people) in rust

    making audiogames (for blind people) in rust

    hello. is it possible to make audiogames in piston? is there a guide to create an audio game in piston? an audiogame is a computer game for the blind that uses only audio to present the gameplay. also we use keyboard only to play games. for example in archery game, you hear a target sound that moves right and left in the stereo sound field. and when it reaches center, you press space to shoot. or in the car racing game, you here the other cars in the stereo field and try to avoid them by turning away. so i am thinking to make audio games in rust. what do I need: create an empty window and catch key presses, play 3d or 2d sound, interact with a screenreader, (tell my active screenreading software to speak a message in a game), (i have a rust lib for that but it's quite old). or speak out the necessary game message using tts or a sound file.

    opened by denizsincar29 2
  • How to get Modifier Keys on Input events?

    How to get Modifier Keys on Input events?


    I'm just getting started with Rust and Piston, but it seems like I already run into an issue. I figured out that I can poll events to get button or press/release events to check which Key was pressed, and I noticed that a modifier key enum is already available too, but I don't seem to be able to actually access that in any way via the button- press/release events. Is there full support for the modifier keys in piston already and if yes, how can I access them?


    opened by Timtam 0
  • Error in piston docs Rectangle.draw method

    Error in piston docs Rectangle.draw method

    The documentation says

    draw_state draw state, draw_state::Default::default() can be used as a default,

    It should be draw_state::DrawState::default() https://docs.piston.rs/piston_window/graphics/rectangle/struct.Rectangle.html#method.draw

    opened by PandaBean18 0
  • Is there a policy for Rustc's edition or minimum supported version?

    Is there a policy for Rustc's edition or minimum supported version?

    Looking around our repos, there are lots of long-living repos some of which are written in 2015 edition style. I think we can improve them by adapting to the newer edition. Is there an edition or MSRV policy we must conform to?

    opened by shinmili 1
  • V0.33.0(Aug 28, 2017)

    A new version of the Piston core is released and the ecosystem has been updated.

    It is strongly recommended to use event traits to handle events. Use E: GenericEvent in generic code. When following this pattern this update will simply require a version bump in "Cargo.toml".

    This release includes the following improvements:

    Better lazy event loop

    In some application modes that do not require animations, one can save CPU cycles by setting EventSettings::lazy to true. The event loop logic has been changed to a version that behaves better under heavy rendering loads. Instead of rendering on each input event, the event loop now waits for the first event and then polls the event queue empty before rendering. This makes applications more responsive.

    The lazy event loop now also got support for benchmark mode. Since most benchmarks are measuring render + updates it is still recommended to disable EventSettings::lazy when measuring game engine performance. An alternative is to use a frame counter.

    New button event

    You can now read scancodes from the window backend using ButtonEvent. This gives you a ButtonArgs struct similar to render and update events. Scancodes are stored inside ButtonArgs to preserve equality checks for the Button enum.

    The PressEvent and ReleaseEvent traits try to preserve the scancode when transforming an event. This makes it possible to write controllers for custom keyboard layouts, e.g. for testing globalization features. If you do not want this behavior, use the ButtonEvent trait when transforming the event.


    Two new enums has been added: Loop and Event. Some variants was moved from Input to Loop. The design is as following:

    pub enum Loop {
    pub enum Event {
        Custom(EventId, Arc<Any + Send + Sync>),

    This solves a design conflict to support custom events while cleanly separating Input. The GenericEvent trait is now only implemented for Event. To convert to Input one can write:

    if let Some(input) = e.into() { call_some_input_function(input); }

    To support custom events in a generic library, use a generic parameter E: GenericEvent. This allows custom window backends and event transformers to e.g. add hardware or network events and change application code without updating libraries.

    Serde integration

    With the deprecation of rustc-serialize, the Piston core is now using serde. Serialization is supported for Input and Loop, but not for Event since custom events are not serializable. Use conversion traits when storing and loading events, for example when replaying user input.

    Source code(tar.gz)
    Source code(zip)
  • V0.23.0(Jun 2, 2016)

    This release adds some new functionality to AdvancedWindow to hide, show and change position of windows. A minor change was made to the BuildFromWindowSettings trait to make it easier to reuse window settings when creating a new window.

    For release notes, see https://github.com/PistonDevelopers/piston/pull/1092

    Source code(tar.gz)
    Source code(zip)
The Piston game engine organization for maintenance and research
Minecraft-esque voxel engine prototype made with the bevy game engine. Pending bevy 0.6 release to undergo a full rewrite.

vx_bevy A voxel engine prototype made using the Bevy game engine. Goals and features Very basic worldgen Animated chunk loading (ala cube world) Optim

Lucas Arriesse 125 Dec 31, 2022
2-player game made with Rust and "ggez" engine, based on "Conway's Game of Life"

fight-for-your-life A 2-player game based on the "Conway's Game of Life", made with Rust and the game engine "ggez". Create shapes on the grid that wi

Petros 3 Oct 25, 2021
2d Endless Runner Game made with Bevy Game Engine

Cute-runner A 2d Endless Runner Game made with Bevy Game Engine. Table of contents Project Infos Usage Screenshots Disclaimer Project Infos Date: Sept

JoaoMarinho 2 Jul 15, 2022
A game made in one week for the Bevy engine's first game jam

¿Quien es el MechaBurro? An entry for the first Bevy game jam following the theme of "Unfair Advantage." It was made in one week using the wonderful B

mike 20 Dec 23, 2022
A Client/Server game networking plugin using QUIC, for the Bevy game engine.

Bevy Quinnet A Client/Server game networking plugin using QUIC, for the Bevy game engine. Bevy Quinnet QUIC as a game networking protocol Features Roa

Gilles Henaux 65 Feb 20, 2023
Solana Game Server is a decentralized game server running on Solana, designed for game developers

Solana Game Server* is the first decentralized Game Server (aka web3 game server) designed for game devs. (Think web3 SDK for game developers as a ser

Tardigrade Life Sciences, Inc 16 Dec 1, 2022
a prototype crate for creating modular and performant 3D CPU particle systems, inspired by Unity's Shuriken Particle System.

bevy_prototype_particles This is a prototype crate for creating modular and performant 3D CPU particle systems, inspired by Unity's Shuriken Particle

James Liu 28 Sep 12, 2022
A no-frills Tetris implementation written in Rust with the Piston game engine, and Rodio for music.

rustris A no-frills Tetris implementation written in Rust with the Piston game engine, and Rodio for music. (C) 2020 Ben Cantrick. This code is distri

Ben Cantrick 17 Aug 18, 2022
A feature-rich, production-ready, general purpose 2D/3D game engine written in Rust with a scene editor.

A feature-rich, production-ready, general purpose 2D/3D game engine written in Rust with a scene editor.

rg3d engine 5.4k Jan 4, 2023
My first Real-Time 3D Game Engine learning project written in Rust.

EyeEngine-Rust FOA, sry for my poor English. What is Eye Engine? Eye Engine is my first Real-Time 3D Game Engine learning project. There are two editi

F-seeeye 4 Jan 5, 2022
A simple Minecraft written in Rust with the Piston game engine

hematite A simple Minecraft written in Rust with the Piston game engine How To Open a World This method is only for personal use. Never distribute cop

PistonDevelopers 1.7k Dec 22, 2022
A block world game engine written in Rust.

About This is the Leafwing Studios' template repo, providing a quick, opinionated base for high-quality Bevy game projects (and libraries). We've shav

null 0 Feb 3, 2022
🐢 Our game engine written in Rust 🦀

tort Our game engine using Vulkan based on Bevy, written in Rust ?? ?? Warning ?? This library is still experimental and should not be used for anythi

Project KML 8 Mar 1, 2023
A refreshingly simple data-driven game engine built in Rust

What is Bevy? Bevy is a refreshingly simple data-driven game engine built in Rust. It is free and open-source forever! WARNING Bevy is still in the ve

Bevy Engine 21.1k Jan 4, 2023
RTS game/engine in Rust and WebGPU

What is this? A real time strategy game/engine written with Rust and WebGPU. Eventually it will be able to run in a web browser thanks to WebGPU. This

Thomas SIMON 258 Dec 25, 2022
unrust - A pure rust based (webgl 2.0 / native) game engine

unrust A pure rust based (webgl 2.0 / native) game engine Current Version : 0.1.1 This project is under heavily development, all api are very unstable

null 368 Jan 3, 2023
Rust implementation of Another World (aka Out of this world) game engine

RustyWorld Rust implementation of Another World (aka Out of this world) game engine. I wanted a fun project to challenge myself while learning Rust, a

Francesco Degrassi 3 Jul 1, 2021
Simple RUST game with the Bevy Engine

Simple RUST Game using the Bevy Engine YouTube videos for this code base: Episode 1 - Rust Game Development tutorial from Scratch with Bevy Engine Epi

null 150 Jan 7, 2023
Rust Game engine 3D (and 2D)

A feature-rich, production-ready, general purpose 2D/3D game engine written in Rust with a scene editor.

rg3d engine 5.4k Jan 9, 2023