DEV Community

Cover image for Why your Godot pixel font is blurry, and the three import settings that fix it
Darrell Best
Darrell Best

Posted on Originally published at angelofcuriosity.itch.io

Why your Godot pixel font is blurry, and the three import settings that fix it

The same Godot 4 labels twice: on the left, Cozy Pixel Fonts with Godot's default import, slightly soft; on the right, the same fonts after three import settings and nearest filtering, with sharp pixels

You dropped a perfectly sharp pixel font into Godot 4, typed a line of dialogue, and the letters came out like they had been left on a warm scanner. The font is not blurry. The import settings are.

Godot's default dynamic-font import is built for smooth TTF text: grayscale antialiasing, light hinting, and subpixel positioning. That is correct for a UI that should look like a document. It is wrong for a font whose every glyph sits on a pixel grid. The three import settings that fix it are:

  1. Antialiasing: None
  2. Hinting: None
  3. Subpixel Positioning: Disabled

Then draw the text with nearest filtering, at a whole-number size. The shot above is a real Godot 4.3 run (Compatibility renderer). The left column is Cozy Acorn, Cozy Lamplight and Cozy Dumpling with the default import (antialiasing=1, hinting=1, subpixel_positioning=1) and linear filtering. The right column is the same three fonts with those three settings set to 0, plus TEXTURE_FILTER_NEAREST. I printed the live FontFile properties from that run to confirm both sides.

1. Import the font, then change three values

Copy the .ttf files into the project, for example to res://fonts/. Select a font in the FileSystem dock, open the Import dock, and set:

  • Antialiasing: None
  • Hinting: None
  • Subpixel Positioning: Disabled

Leave Generate Mipmaps off, and leave Multichannel Signed Distance Field off. Press Reimport.

On disk, the .import file for a crisp copy looks like this (this is the file I used):

antialiasing=0
generate_mipmaps=false
multichannel_signed_distance_field=false
hinting=0
subpixel_positioning=0
Enter fullscreen mode Exit fullscreen mode

Godot's defaults, from the other copy in the same project, were antialiasing=1, hinting=1, subpixel_positioning=1. That is the whole difference between the two columns.

2. Draw at a whole size, with nearest filtering

In Project Settings > Rendering > Textures > Canvas Textures, set Default Texture Filter to Nearest. If your project has to stay on Linear for other art, set it on the label instead:

extends Node
# font_setup.gd: load a pixel font the way the Import dock should be set.

func make_label(font: Font, text: String, size: int, filter_nearest: bool) -> Label:
    var label := Label.new()
    label.text = text
    label.add_theme_font_override("font", font)
    label.add_theme_font_size_override("font_size", size)
    label.add_theme_color_override("font_color", Color("f4efe3"))
    if filter_nearest:
        label.texture_filter = CanvasItem.TEXTURE_FILTER_NEAREST
    else:
        label.texture_filter = CanvasItem.TEXTURE_FILTER_LINEAR
    return label
Enter fullscreen mode Exit fullscreen mode

Use a size that is a whole multiple of the font's base size, or the grid will land on half pixels and look soft even with the import fixed:

  • Cozy Acorn: 10, 20, 30, 40
  • Cozy Lamplight: 12, 24, 36, 48
  • Cozy Dumpling: 22, 44, 66, 88

The comparison scene used Acorn at 10 and 20, Lamplight at 12 and 24, and Dumpling at 22, which are those base sizes and the first doubling.

For a pixel-art game, also set Display > Window > Stretch > Mode to viewport and Scale Mode to integer, with a small base viewport (320x180 or 640x360). That way the whole screen, text included, scales in whole pixels. The comparison scene used a 640x360 viewport, stretched with integer scale, and I saved the 640x360 capture at 2x with nearest-neighbor so the blog image matches what the player sees at 1280x720.

3. Why those three settings

  • Antialiasing paints grey fringe around every stroke. On a 5 pixel capital, that fringe is a large part of the letter.
  • Hinting reshapes outlines to a different grid than the one the font was drawn on. Pixel fonts already are the grid.
  • Subpixel positioning slides glyphs by a fraction of a pixel so spacing looks smoother on a desktop paragraph. A pixel font that has been slid by a third of a pixel is no longer on its own grid.

Mipmaps and Linear filtering cause a similar smear when the text is scaled. They are not in the Import dock's top three, but they will undo the fix if you leave them on.

What I checked

All of this ran in Godot 4.3.stable (Compatibility renderer).

  • After the first import, the default .import values were antialiasing=1, hinting=1, subpixel_positioning=1, generate_mipmaps=false.
  • I set the crisp copies to 0 / 0 / 0, reimported, and loaded both sides at runtime. The running FontFile properties matched: blurry Acorn and Lamplight reported antialiasing=1 hinting=1 subpixel=1 mipmaps=false, crisp copies reported antialiasing=0 hinting=0 subpixel=0 mipmaps=false.
  • The scene wrote before-after.png from that run, 640x360, with both columns on screen at the same time. The image in this post is that capture scaled to 1280x720 with nearest-neighbor, no other retouching.

Sharp text, on purpose

Once those three settings are in place, the font can only look as good as the grid it was drawn on. Cozy Pixel Fonts is three original pixel fonts that share one warm feel: Acorn at 10 px for HUD numbers, Lamplight at 12 px for dialogue, and Dumpling at 22 px for titles and buttons. They ship as TTF, OTF and BMFont, and they stay sharp at the sizes listed above.

Specimen card from the pack, showing the three fonts at their crisp sizes

Grab it here: Cozy Pixel Fonts

Questions: cozy-pixel-fonts@darrellbest.com

Top comments (0)