1

I've been developing a game for android on LibGDX, and I've just found a problem that it seems no one had before. I searched for answers on how to smooth text, and they say two things:

  1. Use FreeType fonts.
  2. Use a MipMap texture filter.

So, I used a FreeType font, and applied the mipmap, and I'm pretty sure the filter is scaling the font down (so, using mipmap), since the font is of size 200 and the real screen is absolutely not that big.

I don't know if I'm making some kind of stupid mistake or something, but I just can't figure out why is this happening, since what I did seems the thing that solves this issue for other people.

So, that's what I did:

I have an assets class with the things I want to load, that (forgetting about the sprites) looks like this:

public static BitmapFont font;

public static void load(){
    FreeTypeFontGenerator fontGen = new FreeTypeFontGenerator(Gdx.files.internal("vaques/OpenSans-Bold.ttf")); //free font from fontsquirrel.com
    FreeTypeFontParameter fontPar = new FreeTypeFontParameter();

    fontPar.size = 200;
    fontPar.color = Color.valueOf("ffffff");
    fontPar.genMipMaps = true;

    font = fontGen.generateFont(fontPar);
    font.getRegion().getTexture().setFilter(TextureFilter.MipMapLinearNearest, TextureFilter.Linear);

    fontGen.dispose();

}

And then, I load the fonts on the create() method in the main class, and I draw them on the Screen.java file. Getting just the texty things it looks like this:

//Outside the constructor (variable declaration part):
OrthographicCamera textCam;
ViewPort textPort;
SpriteBatch textBatch;

//...

//Inside the constructor:
textBatch = new SpriteBatch();
textCam = new OrthographicCamera();
textPort = new ExtendViewport(1600,0,textCam);
textPort.apply(false);

//...

//On the Render() method:
Gdx.gl.glClearColor(0.2f, 0.2f, 0.2f, 1f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

textCam.update();
textBatch.setProjectionMatrix(textCam.combined);

textBatch.begin();
    Assets.font.setColor(Color.valueOf("821201")); //whatever the color
    Assets.font.draw(textBatch,Integer.toString((int) (1/delta)), 80, 2400-40);
textBatch.end(); 

//I draw more text, but it looks the same as this one, just in other colors.

And here a screenshot of that text: It seems I can't post images directly, so here's the link.

The image shows too a part of a circle comming from a 1024x1024 png scaled down through mipmapping. They looked exactly like the text when I was drawing them through the ShapeRenderer, but now they look fine.

Any idea why this is happening?

Rusca8
  • 533
  • 4
  • 11

2 Answers2

0

Is your MAC is supporting FreeType fonts with MipMap texture filter. I'm little bit doubt on this. Confirm.

Vikas
  • 267
  • 2
  • 10
  • Oh. Maybe is not and that's the problem. I just assumed all computers did. How can I check this? – Rusca8 Jul 08 '15 at 10:50
  • Update: Just checked the app on my phone, and it looks weird too. – Rusca8 Jul 08 '15 at 10:57
  • Would you please confirm the resolution or pixel size of your phone screen? – Vikas Jul 08 '15 at 11:20
  • 800x480, but I don't think is an issue about the resolution, since I can play with the size when running on desktop and all sizes look bad. The problem is that there's nothing doing some kind of antialias effect on the text, so it looks aliased. – Rusca8 Jul 08 '15 at 11:33
0

I finally found the answer by myself. It seems the stupid big size of the font was causing the sharpness, instead of helping make the text smooth.

I reduced the size of the viewport used to write text along with the font size (divided both by 2), and now the text is smooth.

Rusca8
  • 533
  • 4
  • 11