Blurred scaled font - font rendering problem (OpenFL 3 cpp mac target)

Hey,

I have a little font rendering problem which was not occurring in OpenFL 2 - text looks blurry. My stage is 205 x 128 px and everything is scaled to window size with scaleX and scaleY parameters. Here is how it looks like:

compiled with -Dnext and

compiled with -Dv2

Setting text to exact position to avoid “half-pixel” placement doesn’t help, nor does any the settings of TextFormat or TextField objects I tried, it looks always the same. Any idea what is causing this?

Did you try another font?
Unlikely but could be the source of the problem.

Yes, it occurs with all fonts I tried, same results with TrueType and OpenType. Normal bitmap and vector graphics renders and scales fine, “blurry edges” problem is just with text.

Perhaps these values should be rounded to avoid “half-pixel” placement. Rounding the position of TextField does not solve the issue, as glyphs are positioned relative to the TextField.

This appearance is exactly what I’d expect from a texture being scaled up with a LINEAR magnification filter instead of NEAREST. The graphics hardware is blending between adjacent pixels for you. If this is the case, changing or moving the font won’t help; it’ll be drawn blurry regardless.

There are a few code paths in OpenFL which text can render by which appear to force smoothing on:

openfl._internal.renderer.TextFieldGraphics.render()
openfl._internal.renderer.opengl.GLRenderer.renderBitmap()

Both pass “true” as a smoothing parameter to another rendering method (graphics.drawTiles() and renderSession.spriteBatch.renderBitmapData() respectively). In short, it looks as though OpenFL 3 is written to always smooth text when it’s scaled up, and there is currently no way to switch this off.

I don’t use NEAREST texture filter at all in my starling-openfl based app, as I can make all display objects snap to pixels just by rounding their positions.
You may lose performance if you change rendering states very often, so you should avoid that when you can.

Happy if you guys have ideas to improve things :slight_smile:

Just writing it here, if anyone (including future me) needs this:

var label:TextField = new TextField();
label.embedFonts = true;
label.antiAliasType = openfl.text.AntiAliasType.ADVANCED; 

fixes the problem. (OpenFL version 3.4.0)

1 Like