#graphics #gamedev #simple #text-image

buffer-graphics-lib

Simple graphics library for buffers

59 releases (17 breaking)

new 0.18.0 Apr 17, 2024
0.16.2 Mar 30, 2024
0.13.0 Dec 27, 2023
0.11.4 Jun 23, 2023
0.7.1 Nov 6, 2022

#363 in Game dev

Download history 135/week @ 2023-12-22 52/week @ 2023-12-29 36/week @ 2024-01-05 5/week @ 2024-01-12 110/week @ 2024-02-16 59/week @ 2024-02-23 5/week @ 2024-03-01 4/week @ 2024-03-08 10/week @ 2024-03-15 3/week @ 2024-03-22 449/week @ 2024-03-29 53/week @ 2024-04-05

516 downloads per month
Used in pixels-graphics-lib

Custom license

375KB
8K 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 for performance as the struct is nearly empty.

Usage

Cargo

In your Cargo.toml file add

buffer-graphics-lib = "0.17.0"

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

Default features: "serde"

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

  • Adds derive Serialize and Deserialize for most structs and enums
  • Enable graphics-shapes/serde

mint

Enable graphics-shapes/mint

Dependencies

~0.7–4MB
~46K SLoC