Crates.io | leafrender |
lib.rs | leafrender |
version | 0.1.0 |
source | src |
created_at | 2019-05-25 14:26:38.370338 |
updated_at | 2019-05-25 14:26:38.370338 |
description | LeafRender is a simply, easy to use library to just get pixels onto the screen, regardless of your platform. |
homepage | |
repository | https://github.com/j-selby/leafrender |
max_upload_size | |
id | 136915 |
size | 99,127 |
LeafRender is a simply, easy to use library to just get pixels onto the screen, regardless of your platform.
Supported on Windows, Linux and the Raspberry Pi.
Other libraries often require huge amounts of bootstrap which simply doesn't make sense for WIP or hobby projects.
Some support is also included for image formats and input.
Import the crate in your Cargo.toml with (assuming Windows/Linux OpenGL):
leafrender = "0.1.0"
In your code, have something like:
use leafrender::input::Input;
use leafrender::render::Drawer;
use leafrender::pos::Rect;
use leafrender::render::Color;
use leafrender::PlatformDrawer;
use leafrender::PlatformInput;
let mut drawer = PlatformDrawer::new("LeafRender Test", 640, 480)
.expect("Failed to create drawer");
let mut input = PlatformInput::new();
while {
input.update(&mut drawer);
input.do_continue()
} {
drawer.start();
drawer.clear(false);
drawer.enable_blending(); // Enable partial transparency.
// Left disabled by default for e.g. Pi
drawer.draw_colored_rect(
&Rect {
x: 100,
y: 100,
width: 50,
height: 50,
},
&Color {
r: 255,
g: 0,
b: 0,
a: 255,
}
);
drawer.end();
}
Want some text?
use crate::render::font::FontCache;
use crate::pos::Position;
let mut font = FontCache::from_bytes(include_bytes!("Lato-Regular.ttf"))
.expect("Unable to load font");
// [...]
// Inside your main loop, ensuring that blending is enabled (simple example above):
font.draw(
"Hello, World!",
&Color {
r: 0,
g: 0,
b: 0,
a: 255,
},
12,
&Position {
x: 50,
y: 50,
},
&mut drawer
;
Or an image?
use image; // image crate
let image = image::load_from_memory(include_bytes!("img.jpg"))
.expect("Failed to load image")
.to_rgba();
let image = drawer.convert_image(&image);
// [...]
// Inside your main loop, ensuring that blending is enabled (simple example above):
drawer.draw_texture(&image, &Position {
x: 150,
y: 150,
});
rusttype
image
LeafRender is licensed under the Apache 2.0 license, available here.