#piston #image #rendering #graphics

graphics_buffer

A buffer which can be used as a render target for Piston’s graphics library. This buffer can be loaded from and/or saved to a file on disk. This allows for things like screenshots in games.

24 releases (5 breaking)

✓ Uses Rust 2018 edition

new 0.6.0 Apr 11, 2019
0.5.6 Feb 21, 2019
0.5.0 Jan 12, 2019
0.4.4 Dec 12, 2018
0.4.3 Nov 19, 2018

#25 in Multimedia

Download history 1/week @ 2018-12-28 23/week @ 2019-01-04 38/week @ 2019-01-11 21/week @ 2019-01-18 8/week @ 2019-01-25 51/week @ 2019-02-01 15/week @ 2019-02-08 14/week @ 2019-02-15 7/week @ 2019-02-22 60/week @ 2019-03-01 7/week @ 2019-03-08 33/week @ 2019-03-15 150/week @ 2019-03-22 11/week @ 2019-03-29 32/week @ 2019-04-05

144 downloads per month
Used in 1 crate

MIT license

124KB
440 lines

Description

This library provides a buffer type, RenderBuffer, which can be used as a render target for Piston's graphics library. This buffer can be loaded from and/or saved to a file on disk. This allows for things like screenshots in games.

There is also an optional feature for RenderBuffer that allows it to be converted into a G2dTexture so that it can be rendered with piston_window. To enable this, add features = ["piston_window_texture"] to the graphics_buffer dependency in your cargo.toml.

API Documentation

Usage

Add this to your cargo.toml :

graphics_buffer = "0.6.0"
piston2d-graphics = "0.30.0"

or, if you want to be able to draw the texture to a window using piston_window :

graphics_buffer = { version = "0.6.0", features = ["piston_window_texture"] }
piston2d-graphics = "0.30.0"
piston_window = "0.89.0"

Here is a simple example that draws three circles and saves the image to a file:

use graphics::ellipse;
use graphics_buffer::*;

fn main() {
    // Create a new RenderBuffer
    let mut buffer = RenderBuffer::new(100, 100);
    buffer.clear([0.0, 0.0, 0.0, 0.0]);

    // Big red circle
    ellipse(
        [1.0, 0.0, 0.0, 0.7],
        [0.0, 0.0, 100.0, 100.0],
        IDENTITY,
        &mut buffer,
    );
    // Small blue circle
    ellipse(
        [0.0, 0.0, 1.0, 0.7],
        [0.0, 0.0, 50.0, 50.0],
        IDENTITY,
        &mut buffer,
    );
    // Small green circle
    ellipse(
        [0.0, 1.0, 0.0, 0.7],
        [50.0, 50.0, 50.0, 50.0],
        IDENTITY,
        &mut buffer,
    );

    // Save the buffer
    buffer.save("circles.png").unwrap();
}

Contributing

Feel free to open an issue or PR if you want to contribute. There are definitely places for improvement, especially in the rendering code.

Dependencies

~5MB
~82K SLoC