The official Piston Window for the Piston game engine
use piston_window::*;
fn main() {
let mut window: PistonWindow =
WindowSettings::new("Hello World!", [512; 2])
.build().unwrap();
while let Some(e) = window.next() {
window.draw_2d(&e, |c, g, _| {
use graphics::*;
clear([0.5, 0.5, 0.5, 1.0], g);
rectangle([1.0, 0.0, 0.0, 1.0], // red
[0.0, 0.0, 100.0, 100.0], // rectangle
c.transform, g);
});
}
}If you want to dive into the world of Piston, then you can start here.
The purpose of this library is to provide an easy-to-use, simple-to-get-started and convenient-for-applications API for Piston.
Sets up:
- piston for the Piston framework
- piston-texture for generic textures
- piston2d-graphics for 2D graphics
- piston2d-wgpu_graphics for 2D rendering
- wgpu for 3D rendering
With the Cargo feature "batteries" turned on:
- bevy for Entity-Component-System (ECS) paradigm
- camera_controllers for 3D camera
- collada for a popular 3D asset format
- dyon for scripting
- gltf for a popular and efficient 3D asset format for game engines
- image for reading and saving image formats
- kira for Audio
- nalgebra for Linear Algebra
- piston-ai_behavior for AI behavior trees
- piston_meta for Meta-Parsing (human readable documents)
- piston2d-sprite for 2D sprite animation
- rapier2d for 2D physics
- rapier3d for 3D physics
- texture_packer for texture packing
- vecmath for vector math
- wavefront_obj for a popular 3D asset format
- winit for platform window features
- winit_window as window back-end
To enable the "batteries" feature, you add the following in "Cargo.toml":
piston_window = { version = "*", features = ["batteries"] }
These libraries are simply reexported under "piston_window::*", e.g. "piston_window::dyon". This means you can add one dependency in your project and get a reasonable set of libraries to build your game.
Notice that some of these libraries have turned off certain features to reduce the number of dependencies. Consult the Cargo documentation to learn how to include more features per dependency.
The impl of BuildFromWindowSettings in this library turns on
WindowSettings::srgb, because it is more backward compatible.
Most images such as those found on the internet use sRGB, that has a non-linear gamma corrected space. When rendering 3D, make sure textures and colors are in linear gamma space to get correct color transformation. Consult the WGPU documentation to learn more about how to do this properly.
For more information about sRGB, see PistonDevelopers/piston#1014
This library is meant to be used in applications only. It is not meant to be depended on by generic libraries. Instead, libraries should depend on the lower abstractions, such as the Piston core.
Ideas or feedback? Open up an issue here.