gpt4 book ai didi

android & libgdx - 禁用模糊渲染

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:07:15 25 4
gpt4 key购买 nike

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

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

对于普通图像,即使我在没有任何缩放的情况下显示整个图像,我希望它看起来像我在计算机屏幕上看到的一样清晰,特别是如果我的设备上有这么好的屏幕(它是 galaxy nexus) .我试图通过使用下一个代码来关闭抗锯齿:

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

我也尝试过将缩放方法设置为各种方法,但没有成功。示例:

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

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

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

当然 libgdx 可以处理这个问题,因为 android 的 api-tests 项目的 opengl 部分可以很好地显示图像。

谁能帮帮我?

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

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

最佳答案

试试这个:

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

关于android & libgdx - 禁用模糊渲染,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9847726/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com