Crate gfx_graphics[−][src]
A Piston 2D graphics back-end using gfx-rs.
Piston-Graphics is a generic library for 2D, part of the Piston ecosystem.
The generic abstraction creates triangles that are sent to the back-end.
Triangles are sent through the Graphics
trait.
How to use gfx_graphics
If you are using the piston_window
library, a Gfx2d
object is created for you.
All you need to do is call e.draw_2d(|c, g| { ... });
If you are not using a window wrapper, you need to create Gfx2d
and GfxGraphics
.
- Create a
Gfx2d
object before the event loop - Call
Gfx2d::draw
withargs.viewport()
from the render event.
Example:
let mut g2d = Gfx2d::new(api_version, &mut factory); let mut events = window.events(); while let Some(e) = events.next(&mut window) { if let Some(args) = e.render_args() { g2d.draw(&mut encoder, &output_color, &output_stencil, args.viewport(), |c, g| { ... } } }
For a working example, see “examples/draw_state.rs”.
The closure |c, g|
passes a Context
and &mut GfxGraphics
object.
Context
contains viewport, transform and draw state information.
When passing this to other functions, you usually write them as:
fn draw_something<G: Graphics>(c: &Context, g: &mut G) { ... }
The purpose is to make code reusable across Piston 2D back-ends.
For more information, consult the documentation of Piston-Graphics.
Modules
ops | Image operations for textures. |
Structs
Gfx2d | The data used for drawing 2D graphics. |
GfxGraphics | Used for rendering 2D graphics. |
Texture | Represents a texture. |
TextureContext | Context required to create and update textures. |
TextureSettings | Texture creation parameters. |
Enums
Error | Create creation or update error. |
Filter | Sampling filter |
Flip | Flip settings. |
Format | Texture format. |
Wrap | Wrap mode |
Traits
CreateTexture | Implemented by textures for creation. |
ImageSize | Implemented by all images to be used with generic algorithms. |
TextureOp | Implemented by texture operations. |
UpdateTexture | Implemented by textures for updating. |
Type Definitions
GlyphCache | Stores textures for text rendering. |