BitmapFont呈现工件 [英] BitmapFont rendering artifacts

查看:244
本文介绍了BitmapFont呈现工件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设置了GUI的缩放以占据整个屏幕(窗口)。控件部件很好,但是字体的缩放非常糟糕 - 还有来自相邻字形的人工制品(因为我认为有一些舍入错误)。

你可以很清楚地看到它在T的右侧:



我试图在Hiero中的填充区域中设置不同的值,但是所有这些值都会影响字体的渲染方式 - 它们会在渲染时在字符之间增加空格,而不仅仅是我想要的纹理。 / p>

任何想法如何解决这个文物?我不想要动态字体生成或多种字体,我希望普通的最近邻居缩放(我正在寻找像素)。我假设这是一个在 libGDX 1.2.0 中的错误。

解决方案

我想了解为了让它正常工作,需要被破解的东西。

要点:缩小所有的字形不要重叠。



我的解决方案在 scala : p>

def fixFonts(fontsMap:ObjectMap [String,BitmapFont]){
def fixFont :BitmapFont){
为{
glyphPage< - font.getData.glyphs.toSeq.filter(_ = NULL)
字形< - glyphPage.toSeq.filter(_ =!空)
} {
glyph.u2 - = 0.001f
}
}

fontsMap.iterator()asInstanceOf [java.util.Iterator的[条目[字符串,位图字体]]]。
asScala.foreach {e => fixFont(e.value)}
}

DEF负载(){
皮肤= manager.get(SKIN_FILE)
fixFonts(skin.getAll(classOf [BitmapFont ]))





编辑(6。在 Scala 2.11.4 LibGDX 1.5.3


I have setup scaling of GUI to occupy whole screen (window). Control widgets are fine, but scaling of fonts is terrible - there are artifacts from neighbouring glyphs (because of some rounding errors I suppose).

You can quite clearly see it on a right side of T:

I tried setting various values in padding area in Hiero, but all those values affect how font is rendered - they add space between characters in rendering, not just to a texture as I wanted.

Any idea how to fix this artifacts? I don't want dynamic font generation or multiple fonts, I want ordinary nearest-neighbour scaling (I'm going for a pixely look). I'm assuming this is a bug in libGDX 1.2.0.

解决方案

After some fiddling around I figured what needs to be hacked in order to get it working.

The gist: shrink all glyphs to not overlap.

My solution in :

  def fixFonts(fontsMap: ObjectMap[String, BitmapFont]) {
    def fixFont(font: BitmapFont) {
      for {
        glyphPage <- font.getData.glyphs.toSeq.filter(_ != null)
        glyph <- glyphPage.toSeq.filter(_ != null)
      } {
        glyph.u2 -= 0.001f
      }
    }

  fontsMap.iterator().asInstanceOf[java.util.Iterator[Entry[String, BitmapFont]]].
    asScala.foreach { e => fixFont(e.value)}
  }

  def load() {
    skin = manager.get(SKIN_FILE)
    fixFonts(skin.getAll(classOf[BitmapFont]))
  }

EDIT(6. 4. 2015): Updated code to work in Scala 2.11.4 and LibGDX 1.5.3.

这篇关于BitmapFont呈现工件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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