From ed58dc39cd660f831de1a0f3aa1bcca06a1481e9 Mon Sep 17 00:00:00 2001 From: gered Date: Sat, 1 Apr 2023 00:49:52 -0400 Subject: [PATCH] add Bitmap texture coordinate sampling convenience method his has some off-by-one issues ... ? looks like it mostly works fine, but i need to investigate more --- ggdt/src/graphics/bitmap/primitives.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ggdt/src/graphics/bitmap/primitives.rs b/ggdt/src/graphics/bitmap/primitives.rs index 1d28b81..507c863 100644 --- a/ggdt/src/graphics/bitmap/primitives.rs +++ b/ggdt/src/graphics/bitmap/primitives.rs @@ -66,6 +66,13 @@ impl Bitmap { *(self.pixels_at_ptr_unchecked(x, y)) } + #[inline] + pub fn sample_at(&self, u: f32, v: f32) -> PixelType { + let x = (u * self.width as f32) as i32 % self.width as i32; + let y = (v * self.height as f32) as i32 % self.height as i32; + unsafe { self.get_pixel_unchecked(x, y) } + } + /// Renders a single character using the font given. #[inline] pub fn print_char(&mut self, ch: char, x: i32, y: i32, opts: FontRenderOpts, font: &T) {