I create my font using the following code:

public BitmapFont createFont(FreeTypeFontGenerator ftfg, float dp)
    FreeTypeFontParameter f = new FreeTypeFontParameter();
    f.size = (int)(dp * Gdx.graphics.getDensity());
    f.color = Color.BLACK;
    f.minFilter = Texture.TextureFilter.Nearest;
    f.magFilter = Texture.TextureFilter.MipMapLinearNearest;
    ftfg.scaleForPixelHeight((int)(dp * Gdx.graphics.getDensity()));
    return ftfg.generateFont(f);

myFont = createFont(new FreeTypeFontGenerator(Gdx.files.internal("Fonts/Roboto-Black.ttf")), 16);

I have some labels to which I set the font using:

Label myLabel= new Label("Text", uiSkin);
        myLabel.getStyle().font = myFont;

How I create the stage:

Stage collectionStage = new Stage(new StretchViewport(Gdx.graphics.getWidth(), Gdx.graphics.getWidth()));

I also tried with no viewport or with other viewports.

In my resize method:

public void resize(int width, int height) {
    Viewport viewport = collectionStage.getViewport();
    viewport.update(width, height, false);

The problem is that when I resize the window on Desktop the font gets distorted. Do I have to create another font in the resize method, and then for each label that I have, reassign the new font? Or should I do something else?

  • \$\begingroup\$ Distorted as in pixelated or as in stretched / other? \$\endgroup\$
    – Charanor
    Jun 20, 2017 at 14:20
  • \$\begingroup\$ Also, if you use a stretch viewport it will stretch your screen and everything in it. Try using a FitViepwort or an ExtendViewport instead that keeps your aspect ratio. \$\endgroup\$
    – Charanor
    Jun 20, 2017 at 15:01

2 Answers 2


You need to use a Viewport which keeps the aspect ratio, for example a FillViewport. This will handle resizing for you, so you "only" need to manage the position. Also, I'd not scale the fonts. Create some fonts in different sizes at the beginning and use them.

  • \$\begingroup\$ I tried to use some of the available viewports, but the fonts still get distorted on resize. \$\endgroup\$
    – Andy
    Mar 24, 2017 at 21:39
  • \$\begingroup\$ Can you upload the code of how you initialize and use the viewport? \$\endgroup\$
    – AlGrande
    Mar 24, 2017 at 22:10
  • \$\begingroup\$ I updated my question with a bit more code. \$\endgroup\$
    – Andy
    Mar 24, 2017 at 22:31

Saw because of bump,

If it comes out blurry than you are most likely using a font that is too small for the resolution you are working at. What you'll want to do is to create a font at the size that is suggested for that font, and then scale it up afterwords.


fontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("Fonts/pixels.ttf"));
FreeTypeFontGenerator.FreeTypeFontParameter fontParameter;
fontParameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
fontParameter.size = 16;
fontParameter.color = Color.WHITE;
font = fontGenerator.generateFont(fontParameter);
// scale here
font.getData().setScale(/*however much you want to scale with*/);

Hope this helps.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .