Crate piston_window
source · [−]Expand description
The official Piston window wrapper for the Piston game engine
Notice! If this is your first time visiting Piston, 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:
- Gfx with an OpenGL back-end.
- gfx_graphics for 2D rendering.
- glutin_window as default window back-end, but this can be swapped (see below).
Example
extern crate piston_window;
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, _| {
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);
});
}
}
The draw_2d
function calls the closure on render events.
There is no need to filter events manually, and there is no overhead.
Swap to another window back-end
Change the generic parameter to the window back-end you want to use.
extern crate piston_window;
extern crate sdl2_window;
use piston_window::*;
use sdl2_window::Sdl2Window;
let window: PistonWindow<Sdl2Window> =
WindowSettings::new("title", [512; 2])
.build().unwrap();
sRGB
The impl of BuildFromWindowSettings
in this library turns on
WindowSettings::srgb
, because it is required by gfx_graphics.
Most images such as those found on the internet uses sRGB,
that has a non-linear gamma corrected space.
When rendering 3D, make sure textures and colors are in linear gamma space.
Alternative is to use Srgb8
and Srgba8
formats for textures.
For more information about sRGB, see https://github.com/PistonDevelopers/piston/issues/1014
Library dependencies
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.
Re-exports
pub extern crate texture;
Modules
A text character
Draw an arc
Helper methods for colors
Transformation context
Back-end agnostic controller events.
Graphics draw state.
Draw ellipse
Event identifiers.
Trait for generic events
Implementations of the CharacterCache
trait.
A flat grid with square cells.
Draw an image
Back-end agnostic keyboard keys.
Draw Line
Various methods for computing with vectors.
Helper functions for computing modular index safely.
Back-end agnostic mouse buttons.
Draw polygon
Reexport radians helper trait from vecmath
Draw rectangle
Draw text
Texture packing.
Methods for converting shapes into triangles.
Contains type aliases used in this library
Structs
After render arguments.
Stores graphics API version.
Button arguments.
Holds rendered character data.
A curved line
Close arguments.
Drawing 2d context.
Components of a controller axis move event. Not guaranteed consistent across backends.
Components of a controller button event. Not guaranteed consistent across backends.
Components of a controller hat move event (d-Pad).
Graphics draw state used for blending, clipping and stencil rendering.
An ellipse with filled color
Stores event loop settings.
An event loop iterator
Idle arguments, such as expected idle time in seconds.
An image
A colored line with a default border radius
A window without user interface, often used in server event loops.
Contains everything required for controlling window, graphics, event loop.
A polygon
Structure to store the window position.
A filled rectangle
Render arguments.
Resize arguments.
Structure to store the window size.
Renders text
Represents a texture.
Context required to create and update textures.
Texture creation parameters.
Touch arguments
An error for when a graphics API is unsupported.
Update arguments, such as delta time in seconds.
Stores viewport information.
Settings structure for window behavior.
Enums
Models different kinds of buttons.
Stores button state.
Models all events.
Models dragging and dropping files.
Sampling filter
Flip settings.
Stores controller hat state.
Models input events.
Represent a keyboard key. Keycodes follows SDL http://wiki.libsdl.org/SDLKeycodeLookup
Models loop events.
Models different kinds of motion.
Represent a mouse button.
Stores the touch state.
Constants
Any triangulation method called on the back-end never exceeds this number of vertices. This can be used to initialize buffers that fit the chunk size.
The default maximum frames per second.
The default updates per second.
The default delayed updates reset.
Traits
Trait representing a window with the most features that are still generic.
After rendering and buffers are swapped.
Constructs a window from a WindowSettings
object.
Changed button state.
Stores characters in a buffer and loads them by demand.
Window is closing.
Implemented by contexts that contains color.
The position of a controller axis changed.
When window gets or loses cursor.
Methods implemented for changing event loop settings.
When window gets or loses focus.
Implemented by all events.
Implemented by all graphics back-ends.
When background tasks should be performed.
Implemented by all images to be used with generic algorithms.
The position of the mouse cursor.
The relative movement of mouse cursor.
The scroll of the mouse wheel.
Trait for OpenGL specific operations on a window.
The press of a button.
Useful constants for radians.
Should be implemented by contexts that have rectangle information.
The release of a button.
When the next frame should be rendered.
When the window is resized.
Should be implemented by contexts that have source rectangle information.
When receiving text from user, such as typing a character.
When a touch is started, moved, ended or cancelled.
Implemented by contexts that can transform.
When the application state should be updated.
Trait representing the minimum requirements for defining a window.
Functions
Draws arc
Clears the screen.
Draws ellipse.
Draws ellipse by corners.
Draws image.
Draws line.
Draws line between points.
Draws polygon.
Draws rectangle.
Draws rectangle.
Draws text.
Type Definitions
2D graphics.
Texture type compatible with G2d
.
Texture context.
Actual device used by Gfx backend.
Actual gfx::Stream implementation carried by the window.
Actual factory used by Gfx backend.
Glyph cache.
The type of an OpenGL function address.
The type of time stamp.