Mercurial > touhou
diff examples/common.rs @ 746:0ebf6467e4ff
examples: Add a menu example.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sat, 18 Jan 2020 19:19:51 +0100 |
parents | 90e907859bae |
children | ee45bfde91bb |
line wrap: on
line diff
--- a/examples/common.rs +++ b/examples/common.rs @@ -45,8 +45,11 @@ fn merge_rgb_alpha(rgb: &DynamicImage, a .collect::<Vec<_>>() } -fn load_rgb_png(surface: &mut GlfwSurface, path: &Path) -> Result<LoadedTexture, TextureLoadError> { - let img = open_rgb_png(&path)?; +pub fn load_from_data(data: &[u8]) -> Result<DynamicImage, ImageError> { + image::load_from_memory(data) +} + +pub fn upload_texture_from_rgb_image(surface: &mut GlfwSurface, img: DynamicImage) -> Result<LoadedTexture, TextureLoadError> { let (width, height) = img.dimensions(); let texels = img .pixels() @@ -65,6 +68,11 @@ fn load_rgb_png(surface: &mut GlfwSurfac Ok(LoadedTexture::Rgb(tex)) } +pub fn load_rgb_texture(surface: &mut GlfwSurface, path: &Path) -> Result<LoadedTexture, TextureLoadError> { + let img = open_rgb_png(&path)?; + upload_texture_from_rgb_image(surface, img) +} + fn load_rgb_a_pngs(surface: &mut GlfwSurface, rgb: &Path, alpha: &Path) -> Result<LoadedTexture, TextureLoadError> { let img = open_alpha_png(&alpha)?; let alpha = match img.grayscale() { @@ -99,7 +107,7 @@ pub fn load_anm_image<P: AsRef<Path>>(mu load_rgb_a_pngs(&mut surface, &png_filename, &alpha_filename) }, None => { - load_rgb_png(&mut surface, &png_filename) + load_rgb_texture(&mut surface, &png_filename) } } }