From 67c133aa0ab205259176d2c210b9ab538f6109ba Mon Sep 17 00:00:00 2001 From: Micha White Date: Thu, 13 Oct 2022 11:50:21 -0400 Subject: Brought back bitmaps --- examples/bmp.rs | 24 ++++++++++++++++++++++-- src/texture.rs | 2 ++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/examples/bmp.rs b/examples/bmp.rs index 5c77318..7b649da 100644 --- a/examples/bmp.rs +++ b/examples/bmp.rs @@ -32,7 +32,7 @@ fn main() { let gator_y = renderer.textures().texture_y(gator_id).unwrap(); renderer.instances_mut().push_instance(Instance { - position: [-0.5, 0.0], + position: [-0.5, 0.5], size: [0.75; 2], texture_size: [gator_width, gator_height], texture_coordinates: [gator_x, gator_y], @@ -52,13 +52,33 @@ fn main() { // TODO we can make a helper function that makes a square to fit a texture renderer.instances_mut().push_instance(Instance { - position: [0.5, 0.0], + position: [0.5, 0.5], size: [0.75; 2], rotation: 0.5, texture_size: [icon_width, icon_height], texture_coordinates: [icon_x, icon_y], ..Default::default() }); + + // render the bitmap alligator + let gator = include_bytes!("res/gator.bmp"); + let gator_id = renderer + .textures_mut() + .load_from_memory(gator, ImageFormat::Bmp) + .unwrap(); + let gator_width = renderer.textures().texture_width(gator_id).unwrap(); + let gator_height = renderer.textures().texture_height(gator_id).unwrap(); + let gator_x = renderer.textures().texture_x(gator_id).unwrap(); + let gator_y = renderer.textures().texture_y(gator_id).unwrap(); + + renderer.instances_mut().push_instance(Instance { + position: [0.0, -0.5], + size: [1.5; 2], + texture_size: [gator_width, gator_height], + texture_coordinates: [gator_x, gator_y], + ..Default::default() + }); + renderer.camera_mut().set_rotation(0.1); renderer.run(event_loop); diff --git a/src/texture.rs b/src/texture.rs index 1002136..ac2dd63 100644 --- a/src/texture.rs +++ b/src/texture.rs @@ -25,6 +25,7 @@ impl TextureId { #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub enum ImageFormat { + Bmp, Ico, Farbfeld, } @@ -32,6 +33,7 @@ pub enum ImageFormat { impl ImageFormat { const fn format(self) -> image::ImageFormat { match self { + Self::Bmp => image::ImageFormat::Bmp, Self::Ico => image::ImageFormat::Ico, Self::Farbfeld => image::ImageFormat::Farbfeld, } -- cgit v1.2.3