问题
I've encountered some issues with LibGDX's filtering. Fonts work fine without using mipmaps, but when I add them the text renders as a series of black boxes.
Here's the method I use to generate a font.
public static BitmapFont generateFont(String fontPath, int size, String chars){
FileHandle fontFile = Gdx.files.internal(fontPath);
FreeTypeFontGenerator generator = new FreeTypeFontGenerator(fontFile);
FreeTypeFontGenerator.FreeTypeFontParameter params = new FreeTypeFontGenerator.FreeTypeFontParameter();
params.size = size;
params.magFilter = TextureFilter.MipMapLinearLinear;
params.minFilter = TextureFilter.MipMapLinearLinear;
params.characters = chars;
BitmapFont f = generator.generateFont(params);
generator.dispose();
return f;
}
Without mipmaps:
![](https://www.eimg.top/images/2020/03/20/a36c504105e38c4e847a00dd9cf4f205.png)
With mipmaps:
![](https://www.eimg.top/images/2020/03/20/03f69242c56f903f209bdd031589efe0.png)
回答1:
Set params.genMipMaps = true
before generating your font.
Also, it doesn't make sense to use mip-maps for your mag filter. Not sure if it could cause problems on some devices, but I would just set it to Linear.
来源:https://stackoverflow.com/questions/24544244/libgdx-fonts-with-mipmapping-drawn-as-black-squares