mirror of
https://github.com/ocornut/imgui.git
synced 2026-11-08 19:02:56 +00:00
Blurry rendering of alternate rows of text with non-integer font height #6800
Labels
No labels
accidentally closed
android
backends
bug
building
clipper
coloredit
color spaces
cplusplus
data types
demo
disabled
doc
docking
dpi
drag drop
drawing/drawlist
dropped
dx12
enhancement
focus
font/text
gallery
help wanted
idle/power saving
ime
in progress
inputs
inputtext
internals
label/id and id stack
language bindings
layout
linux/bsd
menus
multi-contexts
multi-threading
multi-viewports
nav
news/info
opengl
optimization
osx/ios
overlap
plot/graph
popups
question
scrolling
selection
settings
sliders/drags
style
tables/columns
tabs
test wanted
tools
tooltips
tree
tricks & tips
useful widgets
vulkan
web
window pos/depth
window sizing
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
ocornut/imgui#6800
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I'm using imgui 1.89.8 with Vulkan backend on Linux and a custom font (DejaVu Sans 12/14px and DejaVuSans Mono 12px are all affected so far, have not tried others yet).
Any time I display a single line of text, no matter how many widgets I stack in a window, everything looks fine.
But if I have a single multi-line text block the second, fourth, and successive even-numbered lines of text will appear blurry. I think this is the result of line height being a fraction of a pixel, so successive lines are displaced by about half a pixel relative to the first line and the texture doesn't map 1:1 to screen pixels.
According to the "fonts" tab of the demo window, the fonts are all fractional pixels in height despite me having asked for integer pixel size (12.46px for 12px, 14.38px for 14px).
Is there some setting I can poke to fix this? Is this a problem with how TTF fonts are loaded into the font atlas?
Update: I was calling atlas->AddFontFromFileTTF with the target pixel size multiplied by the content scale, and no rounding. Rounding this to the nearest pixel removed the alternating line blur, and I got a further quality improvement by setting config.PixelSnapH.
So I guess this is just a problem in general with fonts that have a height that isn't an integer number of pixels? I expected the text to simply antialias a bit further off the edge of the pixel but it seems somewhere either the font atlas or the rendered polygons are an integer number of pixels while the other is not, so the resulting resampling blurs everything vertically.
Yes we don't technically support that properly yet unfortunately, and it has been causing lots of subtle issues. you'll need to round your numbers at loading times.
I haven't tested but I suspect if you use OversampleV = 2 it might improve the look, but expect other subtle bugs.
I've been hesitant to perform the rounding at load times for some reasons but I think I will backtrack on that and round the numbers at load time until we can improve the logic.
I added enforcing of font size rounding in
bd63a9fNote that using io.FontGlobalScale or SetWindowFontScale(), with are legacy-ish/partially supported features but sitll somehow convenient in some situation, can still lead to unrounded sizes and same issues.