#graphics #gamedev #simple

buffer-graphics-lib

Simple graphics library for buffers

14 releases (6 breaking)

Uses new Rust 2021

0.7.1 Nov 6, 2022
0.7.0 Sep 16, 2022
0.6.4 Sep 12, 2022
0.5.0 Sep 7, 2022
0.1.0 Sep 3, 2022

#288 in Game dev

Download history 155/week @ 2022-09-02 142/week @ 2022-09-09 59/week @ 2022-09-16 7/week @ 2022-09-23 49/week @ 2022-09-30 17/week @ 2022-10-07 3/week @ 2022-10-14 16/week @ 2022-10-21 6/week @ 2022-10-28 59/week @ 2022-11-04 10/week @ 2022-11-11 13/week @ 2022-11-18 28/week @ 2022-11-25

111 downloads per month
Used in pixels-graphics-lib

Custom license

175KB
4K SLoC

Buffer Graphics Lib

This is a simple graphics library for drawing to a buffer, mainly designed to be used with Rust Graphics Library or Pixels

It has basic shape drawing, bitmap text and image rendering.

The Graphics struct needs a mutable slice to work on and so mostly likely you'll need to create the struct and pass in the buffer from the rendering library every frame.

Usage

Cargo

In your Cargo.toml file add

buffer-graphics-lib = "0.7.0"
graphics-shapes = "0.1.4"

Code

Setup a graphics instance

let mut buffer: [u8; 1920000] = [0; 800 * 600 * 4]; //800 x 600 RGBA 
let mut graphics = Graphics::new(&mut buffer, 800, 600)?;

Drawing is then quite simple:

let text = Text::new("Some text", (1,1), (WHITE, Large));
graphics.draw(&text);
graphics.draw_image(20, 20, &image);
let shape = Rect::new((10,10),(50,50));
let drawable = Drawable::from_obj(shape, stroke(BLUE));
graphics.draw(&drawable);

Features

Both are enabled by default

image_loading

Load files as Images

Code

let image = load_image("resources/example.png")?;
graphics.draw_image(40, 20, &image);

serde_derive

Adds derive Serialize and Deserialize for Rect

Dependencies

~0.3–2.8MB
~42K SLoC