libgdx纹理过滤器和mipmap [英] libgdx texture filters and mipmap

查看:105
本文介绍了libgdx纹理过滤器和mipmap的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试在LibGDX中使用Mipmap过滤时,没有图像出现.

When I try to use mipmap filtering in LibGDX, none of the images appear.

我是LibGDX的新手,我有一个简单的2D场景,其中包含三个旋转且缩放的圆圈.为了消除锯齿,我想使用线性滤波.为了寻求建议,我查看了这篇文章,该文章说,对于大规模缩放的图像,可以使用mipmap来提高速度或质量.

I'm new to LibGDX, and I have a simple 2d scene with three rotating, scaled circles. In order to anti-alias them, I wanted to use linear filtering. For advice, I looked to this article,which said that, for heavily scaled images, a mipmap can be used to improve speed or quality.

第一个意外的出现是,尽管事实上我的所有图像都按比例缩小,但是如果magFilter是线性的,我只会看到线性滤波器.换句话说:

The first unexpected appearance was that, despite the fact that all of my images were scaled down, I would only see a linear filter if the magFilter was linear. In other words:

此代码将显示缩小图像的线性过滤器:

parentTexture.setFilter(TextureFilter.Nearest, TextureFilter.Linear);

此代码不会:

parentTexture.setFilter(TextureFilter.Linear, TextureFilter.Nearest);

似乎与libGDX函数相反:

void com.badlogic.gdx.graphics.Texture.setFilter(TextureFilter minFilter, TextureFilter magFilter)

这不会打扰我,除了它表明libgdx错误(不太可能),文章错误(不太可能)或者我不了解纹理过滤器.当我尝试使用mipmap过滤器时,后者似乎特别有可能.

This would not bother me, except that it indicates that either libgdx is wrong (unlikely), the article is wrong (unlikely), or I don't understand texture filters. The latter seems especially likely when I try mipmap filters.

此代码不会显示任何内容

parentTexture.setFilter(TextureFilter.MipMapLinearLinear, TextureFilter.Linear);

此代码显示,但具有最近的过滤条件

parentTexture.setFilter(TextureFilter.Linear, TextureFilter.MipMapLinearLinear);

对我错在哪里的任何解释将不胜感激.我在其他地方进行了搜索,但是libGDX中的纹理过滤器是非常具体的,因此,除了本文之外,我没有找到太多帮助.

Any explanation of where I'm wrong would be greatly appreciated. I have searched elsewhere, but texture filters in libGDX is pretty specific, so aside from the article, I haven't found much to help.

推荐答案

我遇到了同样的问题,而且修复非常简单.创建Texture时,需要指定它使用mipmap.

I had this same problem, and the fix turned out to be insanely simple. When you create a Texture, you need to specify that it uses mipmaps.

您要做的就是像这样将第二个参数传递给Texture构造函数:

All you have to do is pass a second parameter to the Texture constructor like this:

Texture myTexture = new Texture(Gdx.files.internal("myImage.png"), true);

您可以在以下API文档中查看所有Texture类构造函数:

You can view all the Texture class constructors in the API docs here: http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/Texture.html

这篇关于libgdx纹理过滤器和mipmap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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