LibGDX 大 FreeType MipMapped 字体看起来像素化

LibGDX Big FreeType MipMapped font looks pixelated

我一直在 LibGDX 上为 android 开发游戏,我刚刚发现了一个以前似乎没有人遇到过的问题。我搜索了有关如何平滑文本的答案,他们说了两件事:

  1. 使用 FreeType 字体。
  2. 使用 MipMap 纹理过滤器。

所以,我使用了 FreeType 字体,并应用了 mipmap,我很确定过滤器正在缩小字体(因此,使用 mipmap),因为字体大小为 200,而实际屏幕是绝对没有那么大。

我不知道我是不是犯了一些愚蠢的错误,但我就是想不通为什么会这样,因为我所做的似乎为其他人解决了这个问题.

所以,这就是我所做的:

我有一个资产 class,里面有我想要加载的东西,(忘记精灵)看起来像这样:

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();

}

然后,我在主 class 中的 create() 方法中加载字体,并在 Screen.java 文件中绘制它们。只获取文本内容,如下所示:

//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.

这里是该文本的屏幕截图: It seems I can't post images directly, so here's the link.

该图像也显示了来自 1024x1024 png 通过 mipmap 缩小的圆圈的一部分。当我通过 ShapeRenderer 绘制它们时,它们看起来与文本完全一样,但现在它们看起来很好。

知道为什么会这样吗?

您的 MAC 是否支持 带有 MipMap 纹理过滤器的 FreeType 字体。我对此有点怀疑。确认。

我终于自己找到了答案。看起来愚蠢的大字体导致了清晰度,而不是帮助使文本流畅。

我减小了用于写入文本的视口大小以及字体大小(均除以 2),现在文本很流畅。