LibGDX FreeType 字体模糊

LibGDX FreeType font blurry(LibGDX FreeType 字体模糊)
本文介绍了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)

我有以下问题:(大字体中断并且看起来非常模糊,但仅在 medium 上.Largesmall 看起来非常清晰)

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

我的预设字体大小:

//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 的幂才能是偶数?)

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.

有人可以帮我吗?

推荐答案

我想通了,如果你想要极致清晰的字体,你需要设置 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));

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

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;

这将为您提供在任何分辨率下都非常漂亮的清晰字体.总账.

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

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

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Show padding zeros using DecimalFormat(使用 DecimalFormat 显示填充零)
Java decimal formatting using String.format?(使用 String.format 的 Java 十进制格式?)
Sprintf equivalent in Java(Java 中的 Sprintf 等价物)
StAX XML formatting in Java(Java 中的 StAX XML 格式)
Java - format double value as dollar amount(Java - 将双值格式化为美元金额)
Java printf using variable field size?(Java printf使用可变字段大小?)