LibGDX FreeType字体模糊

时间:2014-07-13 21:57:16

标签: java android opengl-es libgdx freetype

我正在使用屏幕高度百分比动态生成我的字体并设置百分比(显然将在未来乘以密度。

一些笔记。 我正在读OTF文件。 使用最新版本的LibGDX(版本1.2.0)

我有以下问题: (字体大而且看起来非常模糊,但仅限于中等看起来非常清晰)

Bad font

我的预设字体大小:

//Font sizes, small, med, large as a percentage of the screen.
    public static float
            FONT_SIZE_LARGE = 0.175f,
            FONT_SIZE_MEDIUM = 0.06f,
            FONT_SIZE_SMALL = 0.04f;

我的字体生成器设置

FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
        FreeTypeFontGenerator generator;
this.generator = new FreeTypeFontGenerator(Gdx.files.internal(filename));

创建实际字体:

//Create a new font and add it to available font sizes.
public BitmapFont createFont(float size, float color)
{
    this.parameter.size = Math.round(size);
    BitmapFont bitmapFont = generator.generateFont(parameter);
    bitmapFont.setColor(color);
    listOfFonts.add(new FontStorage(bitmapFont, size));
    return bitmapFont;
}

现在我在不同的设备上尝试了一些东西,但仍然有同样的问题。我想它可能是因为它不是2的力量? (字体需要是2的幂才能是偶数吗?)

字体是在许多不同的屏幕分辨率上绘制的,因此制作一定大小的三种位图字体是不可能的。

有人可以帮助我吗?

1 个答案:

答案 0 :(得分:3)

我想到了这一点,如果你想要最终的清晰字体,你需要设置3个设置。

前两个是在从文件创建之前(可以是OTF或TTF),它们是:

//Make sure you ceil for your current resolution otherwise you'll be nasty cut-offs.
this.parameter.size = (int)Math.ceil(size);
this.generator.scaleForPixelHeight((int)Math.ceil(size));

下一步是设置放大并缩小过滤器。 (如果你想要缩放,我不是因为我画的像素几乎完美)。无论如何这里是代码:

this.generator = new FreeTypeFontGenerator(Gdx.files.internal(filename));
this.parameter.minFilter = Texture.TextureFilter.Nearest;
this.parameter.magFilter = Texture.TextureFilter.MipMapLinearNearest;

这将为您提供任何分辨率的超级清晰字体。 GL。

相关问题