LibGDX fonts with mipmapping drawn as black squares

雨燕双飞 提交于 2019-12-11 00:54:12

问题


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:

With mipmaps:


回答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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!