Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Piston and You: A Practical Introduction

Piston and You: A Practical Introduction

A quick workshop about graphics and input in Rust.

Mike MacDonald

September 28, 2016
Tweet

Other Decks in Programming

Transcript

  1. What’s a Piston? A piston is a component of reciprocating

    engines, reciprocating pumps, gas compressors and pneumatic cylinders, among other similar mechanisms. It is the moving component that is contained by a cylinder and is made gas-tight by piston rings.
  2. What’s ? Piston is a collection of libraries for game

    development (and related concerns) in Rust. Several libraries that are part of the Piston project are also used outside it: image, for example Piston aims to work seamlessly with a variety of graphics backends: SDL2, glutin, gfx
  3. Let’s get a skeleton. (Spooky.) This assumes you have Rust

    and Cargo installed cargo new --bin pistone cd pistone cargo run
  4. Adding Piston Hello World is not as exciting as it

    used to be Let’s actually add Piston, and get GUI with it Insert into Cargo.toml cargo run
  5. Once more, with graphics? Pulling down and compiling these deps

    will take a while Let’s write code while we wait! Open up src/main.rs and make it look like the next slide:
  6. Rendering with Intent So rendering whatever happens to be in

    GPU memory is not exactly what we intended. But it’s kinda cool! Let’s instead draw a purple square on a black backdrop:
  7. I Like To Move It Move It Set up some

    variables: Make the rectangle use them: Set up an update event:
  8. Summary This is a complete graphic program with user input

    weighing in at 32 loc. Piston provides a lot of tools to make getting up and running easy This game is a lot less segfaulty than the initial version written in straight C with OpenGL (That last one may be a personal problem…)
  9. Where to Go from Here? Add boundary detection, so the

    square can’t go on a journey Add more objects to the game world Add collision detection Reimplement point 1 in terms of point 3 This is your toy now: You do you.