From 49cbd3fe075ee95fb02a8a564e0c1d89292477bd Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Thu, 16 Apr 2020 23:10:05 +0200 Subject: [PATCH] Fix: properly sample white color (was off by half a texel) --- emigui/src/fonts.rs | 10 +++++++--- emigui/src/mesher.rs | 6 ++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/emigui/src/fonts.rs b/emigui/src/fonts.rs index b4813895..14435533 100644 --- a/emigui/src/fonts.rs +++ b/emigui/src/fonts.rs @@ -69,9 +69,13 @@ impl Fonts { let mut atlas = TextureAtlas::new(512, 8); // TODO: better default? - // Make one white pixel for use for various stuff: - let pos = atlas.allocate((1, 1)); - atlas.texture_mut()[pos] = 255; + // Make the top left four pixels fully white: + let pos = atlas.allocate((2, 2)); + assert_eq!(pos, (0, 0)); + atlas.texture_mut()[(0, 0)] = 255; + atlas.texture_mut()[(0, 1)] = 255; + atlas.texture_mut()[(1, 0)] = 255; + atlas.texture_mut()[(1, 1)] = 255; let atlas = Arc::new(Mutex::new(atlas)); diff --git a/emigui/src/mesher.rs b/emigui/src/mesher.rs index 5bd508c1..a5660880 100644 --- a/emigui/src/mesher.rs +++ b/emigui/src/mesher.rs @@ -8,6 +8,8 @@ use crate::{ types::PaintCmd, }; +const WHITE_UV: (u16, u16) = (1, 1); + #[derive(Clone, Copy, Debug, Default, Serialize)] pub struct Vertex { /// Pixel coordinates @@ -146,7 +148,7 @@ impl Mesher { let n = points.len() as u32; let vert = |pos, color| Vertex { pos, - uv: (0, 0), + uv: WHITE_UV, color, }; let mesh = &mut self.mesh; @@ -192,7 +194,7 @@ impl Mesher { let vert = |pos, color| Vertex { pos, - uv: (0, 0), + uv: WHITE_UV, color, }; let mesh = &mut self.mesh;