diff --git a/egui/src/paint/fonts.rs b/egui/src/paint/fonts.rs index 2aa6df978..e03109e9f 100644 --- a/egui/src/paint/fonts.rs +++ b/egui/src/paint/fonts.rs @@ -87,20 +87,16 @@ impl Fonts { let mut atlas = TextureAtlas::new(512, 16); // TODO: better default? - // Make the top left four pixels fully white: { - let pos = atlas.allocate((2, 2)); + // Make the top left pixel fully white: + let pos = atlas.allocate((1, 1)); assert_eq!(pos, (0, 0)); - let tex = atlas.texture_mut(); - tex[(0, 0)] = 255; - tex[(0, 1)] = 255; - tex[(1, 0)] = 255; - tex[(1, 1)] = 255; + atlas.texture_mut()[pos] = 255; } let atlas = Arc::new(Mutex::new(atlas)); - // TODO: figure out a way to make the wasm smaller despite including a font. Zip it? + // TODO: figure out a way to make the WASM smaller despite including a font. Zip it? let monospace_typeface_data = include_bytes!("../../fonts/ProggyClean.ttf"); // Use 13 for this. NOTHING ELSE. // let monospace_typeface_data = include_bytes!("../../fonts/Roboto-Regular.ttf"); diff --git a/egui/src/paint/tessellator.rs b/egui/src/paint/tessellator.rs index 2312e4066..dd4ff57c3 100644 --- a/egui/src/paint/tessellator.rs +++ b/egui/src/paint/tessellator.rs @@ -15,7 +15,10 @@ use { }; /// The UV coordinate of a white region of the texture mesh. -pub const WHITE_UV: (u16, u16) = (1, 1); +/// The default Egui texture has the top-left corner pixel fully white. +/// You need need use a clamping texture sampler for this to work +/// (so it doesn't do bilinear blending with bottom right corner). +pub const WHITE_UV: (u16, u16) = (0, 0); /// The vertex type. /// @@ -26,8 +29,11 @@ pub struct Vertex { /// Logical pixel coordinates (points). /// (0,0) is the top left corner of the screen. pub pos: Pos2, // 64 bit - /// Texel coordinates in the texture + + /// Texel coordinates in the texture. + /// (0, 0) is the top left corner of the texture. pub uv: (u16, u16), // 32 bit + /// sRGBA with premultiplied alpha pub color: Srgba, // 32 bit } diff --git a/egui_glium/src/painter.rs b/egui_glium/src/painter.rs index 8f6e24ba8..337a988cc 100644 --- a/egui_glium/src/painter.rs +++ b/egui_glium/src/painter.rs @@ -6,7 +6,10 @@ use { paint::{PaintJobs, Triangles}, Rect, }, - glium::{implement_vertex, index::PrimitiveType, program, texture, uniform, Frame, Surface}, + glium::{ + implement_vertex, index::PrimitiveType, program, texture, uniform, + uniforms::SamplerWrapFunction, Frame, Surface, + }, }; pub struct Painter { @@ -108,7 +111,7 @@ impl Painter { void main() { // glium expects linear rgba - gl_FragColor = v_rgba * texture2D`(u_sampler, v_tc).r; + gl_FragColor = v_rgba * texture2D(u_sampler, v_tc).r; } ", }, @@ -255,7 +258,7 @@ impl Painter { let uniforms = uniform! { u_screen_size: [width_points, height_points], u_tex_size: [texture.width as f32, texture.height as f32], - u_sampler: &self.texture, + u_sampler: self.texture.sampled().wrap_function(SamplerWrapFunction::Clamp), }; // Egui outputs colors with premultiplied alpha: