Skip to content

Commit 91bdf9b

Browse files
authored
egui_web: make text thicker and less pixelated (#640)
Closes #516
1 parent 12fd490 commit 91bdf9b

File tree

5 files changed

+20
-6
lines changed

5 files changed

+20
-6
lines changed

egui_demo_lib/src/apps/demo/painting.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ impl Default for Painting {
1212
fn default() -> Self {
1313
Self {
1414
lines: Default::default(),
15-
stroke: Stroke::new(1.0, Color32::LIGHT_BLUE),
15+
stroke: Stroke::new(2.0, Color32::LIGHT_BLUE), // Thin strokes looks bad on web
1616
}
1717
}
1818
}

egui_web/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ All notable changes to the `egui_web` integration will be noted in this file.
88
### Added ⭐
99
* Added support for dragging and dropping files into the browser window.
1010

11+
### Fixed 🐛
12+
* Made text thicker and less pixelated.
13+
1114

1215
## 0.13.0 - 2021-06-24
1316

egui_web/src/webgl1.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,8 @@ impl crate::Painter for WebGlPainter {
367367
}
368368

369369
let mut pixels: Vec<u8> = Vec::with_capacity(texture.pixels.len() * 4);
370-
for srgba in texture.srgba_pixels() {
370+
let font_gamma = 1.0 / 2.2; // HACK due to non-linear framebuffer blending.
371+
for srgba in texture.srgba_pixels(font_gamma) {
371372
pixels.push(srgba.r());
372373
pixels.push(srgba.g());
373374
pixels.push(srgba.b());

egui_web/src/webgl2.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,8 @@ impl crate::Painter for WebGl2Painter {
368368
}
369369

370370
let mut pixels: Vec<u8> = Vec::with_capacity(texture.pixels.len() * 4);
371-
for srgba in texture.srgba_pixels() {
371+
let font_gamma = 1.0 / 2.2; // HACK due to non-linear framebuffer blending.
372+
for srgba in texture.srgba_pixels(font_gamma) {
372373
pixels.push(srgba.r());
373374
pixels.push(srgba.g());
374375
pixels.push(srgba.b());

epaint/src/texture_atlas.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,19 @@ impl Texture {
1717
}
1818

1919
/// Returns the textures as `sRGBA` premultiplied pixels, row by row, top to bottom.
20-
pub fn srgba_pixels(&'_ self) -> impl Iterator<Item = super::Color32> + '_ {
20+
///
21+
/// `gamma` should normally be set to 1.0.
22+
/// If you are having problems with egui text looking skinny and pixelated, try
23+
/// setting a lower gamma, e.g. `0.5`.
24+
pub fn srgba_pixels(&'_ self, gamma: f32) -> impl Iterator<Item = super::Color32> + '_ {
2125
use super::Color32;
22-
let srgba_from_luminance_lut: Vec<Color32> =
23-
(0..=255).map(Color32::from_white_alpha).collect();
26+
27+
let srgba_from_luminance_lut: Vec<Color32> = (0..=255)
28+
.map(|a| {
29+
let a = super::color::linear_f32_from_linear_u8(a).powf(gamma);
30+
super::Rgba::from_white_alpha(a).into()
31+
})
32+
.collect();
2433
self.pixels
2534
.iter()
2635
.map(move |&l| srgba_from_luminance_lut[l as usize])

0 commit comments

Comments
 (0)