Search code examples
fontslibgdx

LibGDX font is blurry


So i am creating font using this code

FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("fonts/font.ttf"));
        FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
        parameter.size =SCREEN_WIDTH/12;
      //  generator.scaleForPixelHeight((int)Math.ceil(SCREEN_WIDTH/12));
        parameter.genMipMaps = true;
      //  parameter.minFilter = Texture.TextureFilter.MipMapLinearLinear;
        parameter.magFilter = Texture.TextureFilter.Linear;
        parameter.borderStraight  =true;
        font = generator.generateFont(parameter);

but font end up being blurry no matter what texture filtering i am using i keep screen resolution low due to performance issues

SCREEN_WIDTH = 180;
SCREEN_HEIGHT = 320 

is there a way to create nice and crisp font on this res, or this is as good as it gets ?


Solution

  • Your font is blurry because it's resolution is too small.

    To solve this you could use the tool Hiero (scroll to the bottom) which is mentioned in the libgdx wiki for creating bitmap fonts.

    Open the tool and select the desired font from your system fonts (or from a file).

    Then use the size option in this tool to set a big resolution for your font, according to your game (size ~50 may be enough).

    Save the font files (.png and .fnt) and use it in your game. Now the font should not be blurry anymore.