LibGDX FreeType字体模糊 [英] LibGDX FreeType font blurry

查看:797
本文介绍了LibGDX FreeType字体模糊的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm generating my font dynamically using the screen height percentage and set percentages (Obviously multiplied by density's in the future.

一些注意事项。
我从OTF文件中读取。
使用最新版本的LibGDX(版本1.2.0)

Some notes. I'm reading from an OTF file. Using the latest version of LibGDX (Version 1.2.0)

我有以下问题:
(在字体大断裂和看起来很模糊,但仅限于 看起来非常锐利)

I have the following problem: (Large breaks in the font and looks very blurry, but only on medium. Large and small look very sharp)

我的preSET字体大小:

My Preset font sizes:

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

我的字体生成设置

My font generator settings

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

创建实际的字体:

Creating the actual font:

//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的功率为什?)

Now I've tried a few things on different devices but still have the same issue. I'm thinking it could be because it's not the power of 2? (Do font's need to be a power of 2 to be even?)

中的字体在许多不同的屏幕分辨率绘制,这样做具有一定规模的三个位图字体是出了问题。

The fonts are drawn on many different screen resolutions, so making three bitmap fonts of a certain size is out of the question.

有人可以帮助我在这里?

Can someone help me out here?

推荐答案

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

I figured this out, there are 3 settings you need to set if you want ultimate clear fonts.

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

The first two are just before creating it from file (Can be OTF or TTF) and they are:

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

下一步是设定放大并minifies滤波器。 (对于如果你想太多扩展,我不是因为我画几乎完美像素)。这里的code总之:

The next step is setting a magnify and minifies filters. (For scaling if you want too, I'm not because I'm drawing almost pixel perfect). Here's the code anyhow:

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

这会给你任何决议超好听清脆的字体。 GL。

This will give you super nice crisp font on any resolution. GL.

这篇关于LibGDX FreeType字体模糊的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆