79 breaking releases

Uses old Rust 2015

0.81.0 May 21, 2024
0.80.0 Sep 26, 2023
0.79.0 Nov 18, 2022
0.76.0 Feb 23, 2022
0.4.0 Jul 9, 2015

#541 in Graphics APIs

Download history 2962/week @ 2024-07-22 2888/week @ 2024-07-29 2708/week @ 2024-08-05 4353/week @ 2024-08-12 2618/week @ 2024-08-19 2987/week @ 2024-08-26 2993/week @ 2024-09-02 2815/week @ 2024-09-09 2610/week @ 2024-09-16 3517/week @ 2024-09-23 2677/week @ 2024-09-30 338/week @ 2024-10-07 2244/week @ 2024-10-14 2262/week @ 2024-10-21 2826/week @ 2024-10-28 2331/week @ 2024-11-04

9,693 downloads per month
Used in 74 crates (3 directly)

MIT license

34KB
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

~4.5MB
~91K SLoC