#graphics #2d #gfx #piston

piston2d-gfx_graphics

A Gfx 2D back-end for the Piston game engine

71 breaking releases

Uses old Rust 2015

0.73.0 Apr 12, 2021
0.72.0 Nov 12, 2020
0.71.1 Nov 11, 2020
0.68.0 Feb 10, 2020
0.4.0 Jul 9, 2015

#394 in Game dev

Download history 1826/week @ 2021-02-26 2757/week @ 2021-03-05 1951/week @ 2021-03-12 1819/week @ 2021-03-19 1553/week @ 2021-03-26 1223/week @ 2021-04-02 1867/week @ 2021-04-09 1532/week @ 2021-04-16 1485/week @ 2021-04-23 1569/week @ 2021-04-30 2169/week @ 2021-05-07 1355/week @ 2021-05-14 1174/week @ 2021-05-21 1568/week @ 2021-05-28 1717/week @ 2021-06-04 1725/week @ 2021-06-11

7,736 downloads per month
Used in 56 crates (3 directly)

MIT license

33KB
742 lines

gfx_graphics Build Status

Maintainers: @Potpourri, @kvark, @bvssvni

The implementation of a piston-graphics back-end using Gfx.

API Documentation

screenshot

Dependency graph

dependencies

How to contribute


lib.rs:

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.

  1. Create a Gfx2d object before the event loop
  2. Call Gfx2d::draw with args.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.

Dependencies

~5MB
~74K SLoC