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

Alternative scalable font type? #1392

Closed
slime73 opened this issue Mar 22, 2018 · 9 comments
Closed

Alternative scalable font type? #1392

slime73 opened this issue Mar 22, 2018 · 9 comments
Labels
feature New feature or request

Comments

@slime73
Copy link
Member

slime73 commented Mar 22, 2018

Original report by jarodwright (Bitbucket: jarodwright, ).


Because fonts are rasterized, when applying a transform to a font it doesn't scale well like most other draw functions.

For performance reasons rasterizing should be kept, however I propose that an alternative dynamic font which renders characters each frame would be desirable for scaling text.

An argument against this would be that you shouldn't ever be drawing text to the world and should instead be drawing it to the UI at a screen position based on the world.

@slime73
Copy link
Member Author

slime73 commented Apr 5, 2018

Original comment by Sasha Szpakowski (Bitbucket: slime73, GitHub: slime73).


LÖVE can load BMFont files, and there are tools to produce BMFont glyph atlases which use signed distance fields for the glyphs. You can then write a shader which renders those. https://github.com/libgdx/libgdx/wiki/Distance-field-fonts

It might be worth looking into making a shader included by default in LÖVE for that, although I'm not sure how useful that would be since typically you'd want to tailor things a bit to how your game is going to use the distance field font. Some documentation on the wiki about this would be good, in any case.

@kruncher
Copy link

kruncher commented Jan 3, 2021

Definite +1 here, I did search for SDF so missed this issue. Adding SDF to the comments so that it will be found for anyone else searching for that.

@kruncher
Copy link

kruncher commented Jan 3, 2021

The Unity engine does a good job at implementing SDF text rendering with its TextMesh Pro component. It might be a good reference implementation. It would be good if the render function allowed the font size to be specified each time love.graphics.printSdf("Hello", 32, 0, 0) or alternatively if there was a font size state love.graphics.setFontSize(32).

@slime73
Copy link
Member Author

slime73 commented Jan 3, 2021

All that you need is a shader that works with distance field font glyphs and a love.graphics.setShader call before printing text, everything else is already supported by love (for example love.graphics.print accepts scale parameters already, and love.graphics.newFont accepts BMFonts which can have SDF glyphs).

@Labrium
Copy link
Contributor

Labrium commented Sep 1, 2023

Upgrading FreeType to 2.11.0 or later would allow Löve to use its SDF render mode to output SDF glyphs from any font. I already have a working proof of concept (adding "sdf" HintingMode paired with a shader)

(excuse the experimental subpixel font test)
Screen Shot 2022-10-14 at 5 02 46 PM

Screen Shot 2022-10-14 at 6 48 26 PM

I'll probably clean it up and open a PR soon.

@Labrium
Copy link
Contributor

Labrium commented Sep 1, 2023

For now I've figured out you can use a simple shader that will use the antialiasing as a small section of a distance field, although it only works for upscaling:

uniform float scl; // the scale factor you use to draw the text
vec4 effect(vec4 color, Image texture, vec2 tc, vec2 sc) {
	vec4 c = gammaToLinear(color);
	float d = clamp(Texel(texture, tc).a * scl - 0.5 * scl + 0.5, 0.0, 1.0);
	return linearToGamma(vec4(c.rgb, c.a * d));
}

@kruncher
Copy link

kruncher commented Sep 1, 2023

@Labrium it would be cool if you did open a PR for this :D I am still wanting this

@Labrium
Copy link
Contributor

Labrium commented Sep 2, 2023

#1966 :)

@slime73
Copy link
Member Author

slime73 commented Jun 29, 2024

This is implemented now.

@slime73 slime73 closed this as completed Jun 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants