0

I'm programming a game in LibGDX, but when I try to display some text on the screen with a TrueType font (.ttf), it comes out somewhat blurry. Low Resolution Text Why is this happening?

This is how I'm using the text in my code, implemented from this thread How to draw smooth text in libgdx?:

    stage = new Stage(viewport, game.batch);

    table = new Table();
    table.center();
    table.setFillParent(true);

    generator = new FreeTypeFontGenerator(Gdx.files.internal("Lato-Bold.ttf"));
    parameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
    parameter.size = 30;
    parameter.color = Color.WHITE;
    parameter.characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    font = generator.generateFont(parameter);

    generator.dispose();

    Label.LabelStyle labelStyle = new Label.LabelStyle(font, font.getColor());

    touchToStartLabel = new Label("Touch To Start", labelStyle);

    table.add(touchToStartLabel);

    stage.addActor(table);

Any ideas on how I can get a better rendered text? It's been bugging me for a while.

EDIT: I tried to use trilinear filtering by changing the code to this (and I'm using a FitViewport in case that's important):

 generator = new FreeTypeFontGenerator(Gdx.files.internal("Lato-Bold.ttf"));
    parameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
    parameter.size = 30;
    parameter.color = Color.WHITE;
    parameter.minFilter = Texture.TextureFilter.MipMapLinearLinear;
    parameter.magFilter = Texture.TextureFilter.Linear;
    parameter.characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    font = generator.generateFont(parameter);
    font.setUseIntegerPositions(false);

All I got was this (at least the squares are sharp):What happened?

Community
  • 1
  • 1
Eames
  • 321
  • 2
  • 19
  • If you're not using a ScreenViewport for your text, make sure it has trilinear filtering (MipMapLinearLinear, Linear) and setUseIntegerPositions(false) – Tenfour04 Oct 21 '16 at 16:53
  • On which object? `font`? I don't really get how to do it – Eames Oct 21 '16 at 17:01
  • 3
    `parameter.minFilter = TextureFilter.MipMapLinearLinear;` `parameter.magFilter = TextureFilter.Linear;` and `font.setUseIntegerPositions(false);` – Tenfour04 Oct 21 '16 at 19:15
  • I tried, but it messed it up (I'm not using a ScreenViewport by the way). Check the edit – Eames Oct 21 '16 at 19:32
  • 2
    Also add `parameter.genMipMaps = true;`. – Tenfour04 Oct 22 '16 at 02:09
  • Thanks! It's still slightly out of focus, but it's a definite improvement over what it was before – Eames Oct 22 '16 at 10:10

0 Answers0