Expand description
A library for 2D graphics that works with multiple back-ends.
Piston-Graphics was started in 2014 by Sven Nilsen to test back-end agnostic design for 2D in Rust. This means generic code can be reused across projects and platforms.
§Design
A graphics back-end implements the Graphics
trait.
This library uses immediate design for flexibility. By default, triangles are generated from 2D shapes and passed in chunks to the back-end. This behavior can be overridden by a back-end library.
The structures used for drawing 2D shapes contains settings for rendering.
The separation of shapes and settings allows more reuse and flexibility.
For example, to render an image, you use an Image
object.
The math
module contains useful methods for 2D geometry.
Context
stores settings that are commonly shared when rendering.
It can be copied and changed without affecting any global state.
At top level, there are some shortcut methods for common operations.
For example, ellipse
is a simplified version of Ellipse
.
Re-exports§
pub use character::Character;
pub use character::CharacterCache;
pub use circle_arc::CircleArc;
pub use context::Context;
pub use draw_state::DrawState;
pub use ellipse::Ellipse;
pub use image::Image;
pub use line::Line;
pub use polygon::Polygon;
pub use rectangle::Rectangle;
pub use text::Text;
Modules§
- character
- A text character
- circle_
arc - Draw an arc
- color
- Helper methods for colors
- context
- Transformation context
- draw_
state - Graphics draw state.
- ellipse
- Draw ellipse
- glyph_
cache - Implementations of the
CharacterCache
trait. - grid
- A flat grid with square cells.
- image
- Draw an image
- line
- Draw Line
- math
- Various methods for computing with vectors.
- modular_
index - Helper functions for computing modular index safely.
- polygon
- Draw polygon
- radians
- Reexport radians helper trait from vecmath
- rectangle
- Draw rectangle
- text
- Draw text
- texture_
packer - Texture packing.
- triangulation
- Methods for converting shapes into triangles.
- types
- Contains type aliases used in this library
Structs§
- Viewport
- Stores viewport information.
Constants§
- BACK_
END_ MAX_ VERTEX_ COUNT - 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.
Traits§
- Colored
- Implemented by contexts that contains color.
- Graphics
- Implemented by all graphics back-ends.
- Image
Size - Implemented by all images to be used with generic algorithms.
- Radians
- Useful constants for radians.
- Rectangled
- Should be implemented by contexts that have rectangle information.
- Source
Rectangled - Should be implemented by contexts that have source rectangle information.
- Transformed
- Implemented by contexts that can transform.
Functions§
- circle_
arc - Draws arc
- clear
- Clears the screen.
- ellipse
- Draws ellipse.
- ellipse_
from_ to - Draws ellipse by corners.
- image
- Draws image.
- line
- Draws line.
- line_
from_ to - Draws line between points.
- polygon
- Draws polygon.
- rectangle
- Draws rectangle.
- rectangle_
from_ to - Draws rectangle.
- text
- Draws text.