Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

egui_web: make text thicker and less pixelated #640

Merged
merged 1 commit into from
Aug 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion egui_demo_lib/src/apps/demo/painting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ impl Default for Painting {
fn default() -> Self {
Self {
lines: Default::default(),
stroke: Stroke::new(1.0, Color32::LIGHT_BLUE),
stroke: Stroke::new(2.0, Color32::LIGHT_BLUE), // Thin strokes looks bad on web
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions egui_web/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ All notable changes to the `egui_web` integration will be noted in this file.
### Added ⭐
* Added support for dragging and dropping files into the browser window.

### Fixed 🐛
* Made text thicker and less pixelated.


## 0.13.0 - 2021-06-24

Expand Down
3 changes: 2 additions & 1 deletion egui_web/src/webgl1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,8 @@ impl crate::Painter for WebGlPainter {
}

let mut pixels: Vec<u8> = Vec::with_capacity(texture.pixels.len() * 4);
for srgba in texture.srgba_pixels() {
let font_gamma = 1.0 / 2.2; // HACK due to non-linear framebuffer blending.
for srgba in texture.srgba_pixels(font_gamma) {
pixels.push(srgba.r());
pixels.push(srgba.g());
pixels.push(srgba.b());
Expand Down
3 changes: 2 additions & 1 deletion egui_web/src/webgl2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,8 @@ impl crate::Painter for WebGl2Painter {
}

let mut pixels: Vec<u8> = Vec::with_capacity(texture.pixels.len() * 4);
for srgba in texture.srgba_pixels() {
let font_gamma = 1.0 / 2.2; // HACK due to non-linear framebuffer blending.
for srgba in texture.srgba_pixels(font_gamma) {
pixels.push(srgba.r());
pixels.push(srgba.g());
pixels.push(srgba.b());
Expand Down
15 changes: 12 additions & 3 deletions epaint/src/texture_atlas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,19 @@ impl Texture {
}

/// Returns the textures as `sRGBA` premultiplied pixels, row by row, top to bottom.
pub fn srgba_pixels(&'_ self) -> impl Iterator<Item = super::Color32> + '_ {
///
/// `gamma` should normally be set to 1.0.
/// If you are having problems with egui text looking skinny and pixelated, try
/// setting a lower gamma, e.g. `0.5`.
pub fn srgba_pixels(&'_ self, gamma: f32) -> impl Iterator<Item = super::Color32> + '_ {
use super::Color32;
let srgba_from_luminance_lut: Vec<Color32> =
(0..=255).map(Color32::from_white_alpha).collect();

let srgba_from_luminance_lut: Vec<Color32> = (0..=255)
.map(|a| {
let a = super::color::linear_f32_from_linear_u8(a).powf(gamma);
super::Rgba::from_white_alpha(a).into()
})
.collect();
self.pixels
.iter()
.map(move |&l| srgba_from_luminance_lut[l as usize])
Expand Down