and*_*per 5 fonts android textures blurry libgdx
我正在试用libgdx作为opengl包装器,我的图形渲染有一些问题:由于某种原因,Android设备上的所有图像(纹理)看起来都有点模糊使用libgdx.这还包括文字(字体).
对于文本,我认为这是因为我使用位图字体,但我找不到替代品 - 我发现有一个名为"gdx-stb-truetype"的库,但我找不到如何下载并使用它.
对于普通图像,即使我没有任何缩放显示整个图像,我希望它看起来像我在电脑屏幕上看到的那样清晰,特别是如果我在设备上有这么好的屏幕(它是星系连接).我试图通过使用下一个代码来关闭抗锯齿:
final AndroidApplicationConfiguration androidApplicationConfiguration=new AndroidApplicationConfiguration();
androidApplicationConfiguration.numSamples=0; //tried the value of 1 too.
...
Run Code Online (Sandbox Code Playgroud)
我也尝试将缩放方法设置为各种方法,但没有运气.例:
texture.setFilter(TextureFilter.Nearest,TextureFilter.Nearest);
Run Code Online (Sandbox Code Playgroud)
作为测试,我发现了一个与设备上看到的分辨率完全相同的清晰图像(720x1184对于galaxy nexus,因为按钮栏),我把它放在了libgdx的背景上app.当然,我必须添加额外的空白区域才能加载文本,因此图像的最终尺寸(包括内容和空白空间)对于宽度和高度仍然是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);
}
Run Code Online (Sandbox Code Playgroud)
小智 2
尝试这个:
TextureRegion.getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4291 次 |
| 最近记录: |