#graphics #gamedev #simple

buffer-graphics-lib

Simple graphics library for buffers

42 releases (10 breaking)

0.11.4 Jun 23, 2023
0.10.11 May 1, 2023
0.10.3 Mar 9, 2023
0.8.3 Dec 13, 2022
0.7.1 Nov 6, 2022

#450 in Game dev

Download history 148/week @ 2023-05-29 21/week @ 2023-06-05 27/week @ 2023-06-12 156/week @ 2023-06-19 15/week @ 2023-06-26 44/week @ 2023-07-03 75/week @ 2023-07-10 20/week @ 2023-07-17 26/week @ 2023-07-24 7/week @ 2023-07-31 43/week @ 2023-08-07 66/week @ 2023-08-14 6/week @ 2023-08-21 90/week @ 2023-08-28 71/week @ 2023-09-04 12/week @ 2023-09-11

182 downloads per month
Used in pixels-graphics-lib

Custom license

200KB
4.5K SLoC

Crates.io Documentation

Buffer Graphics Lib

This is a simple graphics library for drawing to a buffer, mainly designed to be used with Pixels Graphics 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 but this should be fine as the struct is nearly empty.

Usage

Cargo

In your Cargo.toml file add

buffer-graphics-lib = "0.11.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

ici

Load ici image files as IndexedImages

let image: IndexedImage...
graphics.draw_indexed_image(coord, &image);

image_loading

Load png, bmp, etc image files as Images

Code

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

serde_derive

Enabled by default

Adds derive Serialize and Deserialize for DrawType and Color

Dependencies

~0.6–2MB
~40K SLoC