Crates.io | texture_bag |
lib.rs | texture_bag |
version | 0.0.4 |
source | src |
created_at | 2021-01-09 10:39:40.770648 |
updated_at | 2021-01-09 11:50:23.176115 |
description | Simple storage and loader for glium textures |
homepage | |
repository | https://github.com/Asera/texture_bag |
max_upload_size | |
id | 336171 |
size | 10,965 |
This library provides a container to store textures without manual file loading and conversion boilerplate. It also provides single access point to textures, even if they weren't loaded on container init. Library supports lazy loading to load textures from a file on-demand and eager loading to load all textures on container init.
Add to your cargo.toml
[dependencies]
texture_bag = "0.0.1"
First of all, you need to create config file with list of all textures used in your project:
{
"textures": {
"texture_id": "path_to_texture"
}
}
Default filename is texture_config.json
, but you can change it passing actual name and path as one of the parameters on TextureBag init.
fn main() {
// Some preparation code for proper init
let event_loop = glium::glutin::event_loop::EventLoop::new();
let window_builder = glium::glutin::window::WindowBuilder::new().with_title("Foo");
let context = glium::glutin::ContextBuilder::new().with_depth_buffer(24);
let display = glium::Display::new(window_builder, context, &event_loop).unwrap();
// This call will load all textures from config into memory
let mut texture_bag = TextureBag::init_eager(&display, None);
// Lazy init will load only config data for further operations, no texture loading will be made
let mut texture_bag = TextureBag::init_lazy(&display, None);
// Method returns reference to a texture.
// If texture was not loaded before, method will check config, load texture by path and store it into the bag.
let texture = texture_bag.get_texture(String::from("texture_id"), display);
// This method will remove texture from the bag. Texture can be loaded again by calling get_texture.
texture_bag.forget(String::from("texture_id"));
}
Please note that this version is basically alpha version of the project. API might change before it will be stabilized. Further possible improvements: