我一直在 LibGDX 上开发一款 Android 游戏,我刚刚发现了一个似乎以前没有人遇到过的问题。我搜索了有关如何平滑文本的答案,他们说了两件事:
- 使用 FreeType 字体。
- 使用 MipMap 纹理过滤器。
所以,我使用了 FreeType 字体,并应用了 mipmap,并且我很确定过滤器正在缩小字体(因此,使用 mipmap),因为字体大小为 200,而实际屏幕绝对没有那么大。
我不知道我是否犯了某种愚蠢的错误或其他什么,但我就是不明白为什么会发生这种情况,因为我所做的似乎可以为其他人解决这个问题。
所以,这就是我所做的:
我有一个 Assets 类,其中包含我想要加载的内容,(忘记 Sprite )看起来像这样:
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();
}
然后,我在主类中的 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 .
该图像还显示了来自通过 mipmapping 缩小的 1024x1024 png 的圆的一部分。当我通过 ShapeRenderer 绘制它们时,它们看起来与文本一模一样,但现在它们看起来很好。
知道为什么会发生这种情况吗?
最佳答案
您的 MAC 是否支持带有 MipMap 纹理过滤器的 FreeType 字体。我对此有点怀疑。确认。
关于java - LibGDX Big FreeType MipMapped 字体看起来像素化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31290027/