-
-
Notifications
You must be signed in to change notification settings - Fork 183
fix: ensure canvas resolution scales with the parent containers to avoid blurry fonts #585
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
Conversation
This doesn't help, but testing in the browser, I see the issue: the resolution of the element changes with the app. The problem is that when the resolution goes down, the canvas just lacks resolution, and it's normal that the text becomes blurry. I can get crisp text by forcing the canvas to stick to a resolution of 1080p and giving it the styles height:100% and width:100%, so it doesn't overflow from its parent frame. And so, I think it's just a matter of changing the canvas-container so it doesn't lower the resolution of the child canvas too much. I noticed this code in the JS const onResize = () => {
const { width, height, ratio } = snappedAspectRation();
canvas.width = width;
canvas.height = height;
console.log({ width, height, ratio });
canvasContainer.style.setProperty(`width`, `${width}px`);
canvasContainer.style.setProperty(`height`, `${height}px`);
document.documentElement.style.setProperty("--scale", `${ratio}`);
}; It seems like the cause to me. |
It used to be set at 100%, the javascript code that resizes the canvas was made specifically to answer another bug... I'll try digging to remember |
It was that commit: ca3d17f It fixes bug #253 (the commit also fixes #315 incidentally, but that's not important for our purposes) So it seems we have the following options:
or
Another option is to
|
Ah that was why! |
The reason why we aren't letting Godot handle the size are:
All three were fixed in #278 To summarize the reasons for that PR:
In summary, our options:
I will try to set specific percentages in JS, a mix of 2 and 3, and see what happens. Another option would be to overlay the fullscreen button at the bottom or top right, regardless of canvas size. |
This reverts commit d380921.
this commit also fixes the overlay on large screens (it was constricted in the middle)
I allowed the canvas container (a simple div) to resize to specific sizes, but made the canvas fill the entire available space with It's difficult for me to test (my screen is small and 1080p), but I think it's fixed? Functionally, everything works still (interactive areas, fullscreen button alignment, and functionality) on both Firefox and Chromium. |
Just tested in firefox and brave, looking great! |
This is related to #381
Hypothesis
Because Godot uses rendered fonts, they do not resize as sharply as vector fonts. This is especially apparent if the viewport is not a multiple of the original resolution (1920x1080).
Fix
The current PR makes sure the viewport resizes to multiples of
240px
. That is, 240, 480, 720, 960, etc. The hope is that pixel division on even numbers will yield sharper results.This seems to work well enough for me, but it requires more testing.
In parallel, I asked itch to give me access to CSS editing there, so the same setup can be reproduced on the itch page.
Importantly: we cannot ensure sharpness if people have custom zoom values set up. A zoom of 72% will always look bad, no matter what. A scale of 125% will similarly result in a pixel division of 0.625, which will create aliasing on the edges.
If we wanted to go around that, we'd need:
This is also what we would need to do if we want to handle blurriness on Desktops.
It's possible, but I don't know if it is worth it at the moment. Godot 4 has automatic font scaling, so the problem could potentially be less visible once we port.
Other changes
This PR also fixes a few warnings for typescript and adds some documentation to the build script for local web dev debugging. Nothing very important.