gfx_graphics/
lib.rs

1#![deny(missing_docs)]
2#![deny(unreachable_pub)]
3
4//! A [Piston 2D graphics](https://github.com/pistondevelopers/graphics) back-end using [gfx-rs](https://github.com/gfx-rs/gfx).
5//!
6//! Piston-Graphics is a generic library for 2D, part of the Piston ecosystem.
7//! The generic abstraction creates triangles that are sent to the back-end.
8//! Triangles are sent through the `Graphics` trait.
9//!
10//! ### How to use gfx_graphics
11//!
12//! If you are using the [piston_window](https://github.com/pistondevelopers/piston_window)
13//! library, a `Gfx2d` object is created for you.
14//! All you need to do is call `e.draw_2d(|c, g| { ... });`
15//!
16//! If you are not using a window wrapper, you need to create `Gfx2d` and `GfxGraphics`.
17//!
18//! 1. Create a `Gfx2d` object before the event loop
19//! 2. Call `Gfx2d::draw` with `args.viewport()` from the render event.
20//!
21//! Example:
22//!
23//! ```ignore
24//! let mut g2d = Gfx2d::new(api_version, &mut factory);
25//! let mut events = window.events();
26//! while let Some(e) = events.next(&mut window) {
27//!     if let Some(args) = e.render_args() {
28//!         g2d.draw(&mut encoder, &output_color, &output_stencil, args.viewport(), |c, g| {
29//!             ...
30//!         }
31//!     }
32//! }
33//! ```
34//!
35//! For a working example, see "examples/draw_state.rs".
36//!
37//! The closure `|c, g|` passes a `Context` and `&mut GfxGraphics` object.
38//! `Context` contains viewport, transform and draw state information.
39//!
40//! When passing this to other functions, you usually write them as:
41//!
42//! ```ignore
43//! fn draw_something<G: Graphics>(c: &Context, g: &mut G) {
44//!     ...
45//! }
46//! ```
47//!
48//! The purpose is to make code reusable across Piston 2D back-ends.
49//!
50//! For more information, consult the documentation of Piston-Graphics.
51
52#[macro_use]
53extern crate gfx;
54extern crate draw_state;
55extern crate gfx_texture;
56extern crate graphics;
57extern crate shaders_graphics2d as shaders;
58extern crate shader_version;
59
60pub use gfx_texture::*;
61
62pub use back_end::{ Gfx2d, GfxGraphics };
63// pub use glyph::Error as GlyphError;
64// pub use glyph::GlyphCache;
65
66/// Stores textures for text rendering.
67pub type GlyphCache<'a, F, R, C> =
68    graphics::glyph_cache::rusttype::GlyphCache<'a, TextureContext<F, R, C>, Texture<R>>;
69
70mod back_end;