android& libgdx - 禁用模糊渲染

时间:2012-03-23 23:26:13

标签: android fonts textures libgdx blurry

我正在尝试将libgdx作为opengl包装器,我的图形渲染存在一些问题: 出于某种原因,Android设备上的所有图像(纹理)使用libgdx看起来有点模糊。这还包括文字(字体)。

对于文本,我认为这是因为我使用位图字体,但我找不到替代品 - 我发现有一个名为“gdx-stb-truetype”的库,但我不能找到如何下载并使用它。

对于普通图像,即使我没有任何缩放显示整个图像,我希望它看起来像我在电脑屏幕上看到的那样清晰,特别是如果我在设备上有这么好的屏幕(它是星系连接) 。 我试图通过使用下一个代码来关闭抗锯齿:

final AndroidApplicationConfiguration androidApplicationConfiguration=new AndroidApplicationConfiguration();
androidApplicationConfiguration.numSamples=0; //tried the value of 1 too.
...

我也尝试将缩放方法设置为各种方法,但没有运气。例如:

texture.setFilter(TextureFilter.Nearest,TextureFilter.Nearest);

作为测试,我发现了一个与设备上看到的分辨率完全相同的清晰图像(720x1184对于galaxy nexus,因为按钮栏),我把它放在背景上的libgdx应用程序。当然,我必须添加额外的空白区域才能加载texute,所以图像的最终尺寸(包括内容和空白空间)对于宽度和高度仍然是2的幂(1024x2048 in this案件) 。 在桌面应用程序上,它看起来不错。在设备上,它看起来很模糊。

我注意到的一个奇怪的事情是,当我改变设备的方向(水平< =>垂直)时,在旋转动画开始前的很短时间内,我看到的图像和文字都非常好。

肯定libgdx可以处理这个,因为android的api-tests项目的opengl部分显示图像就好了。

任何人都可以帮助我吗?

@ user1130529:我确实使用spritebatch。另外,这是我设置视口的方法。无论我是否选择保持纵横比,都会发生这种情况。

public static final int          VIRTUAL_WIDTH         =720;
public static final int          VIRTUAL_HEIGHT        =1280-96;
private static final float       ASPECT_RATIO          =(float)VIRTUAL_WIDTH/(float)VIRTUAL_HEIGHT;
...
@Override
public void resize(final int width,final int height)
  {
  // calculate new viewport
  if(!KEEP_ASPECT_RATIO)
    {
    _viewport=new Rectangle(0,0,Gdx.app.getGraphics().getWidth(),Gdx.app.getGraphics().getHeight());
    Gdx.app.log("DEBUG","size:"+_viewport);
    return;
    }
  final float currentAspectRatio=(float)width/(float)height;
  float scale=1f;
  final Vector2 crop=new Vector2(0f,0f);
  if(currentAspectRatio>ASPECT_RATIO)
    {
    scale=(float)height/(float)VIRTUAL_HEIGHT;
    crop.x=(width-VIRTUAL_WIDTH*scale)/2f;
    }
  else if(currentAspectRatio<ASPECT_RATIO)
    {
    scale=(float)width/(float)VIRTUAL_WIDTH;
    crop.y=(height-VIRTUAL_HEIGHT*scale)/2f;
    }
  else scale=(float)width/(float)VIRTUAL_WIDTH;
  final float w=VIRTUAL_WIDTH*scale;
  final float h=VIRTUAL_HEIGHT*scale;
  _viewport=new Rectangle(crop.x,crop.y,w,h);
  Gdx.app.log("DEBUG","viewport:"+_viewport+" originalSize:"+VIRTUAL_WIDTH+","+VIRTUAL_HEIGHT+" aspectRatio:"+ASPECT_RATIO+" currentAspectRatio:"+currentAspectRatio);
  }

3 个答案:

答案 0 :(得分:2)

试试这个:

TextureRegion.getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);

答案 1 :(得分:0)

如果您有Chainfire 3D应用程序或其他减少纹理或将其更改为16位的应用程序,请将其关闭;这对我有用,我遇到了同样的问题。

答案 2 :(得分:0)

尝试以下方法:

texture.setFilter(TextureFilter.Nearest,TextureFilter.Nearest);

有几种类型的TextureFilters。我假设线性的(默认情况下?)模糊不清。