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:
- Use FreeType fonts.
- 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?