libgdx texture filters and mipmap(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
类构造函数:http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/Texture.html
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:libgdx 纹理过滤器和 mipmap
基础教程推荐
- 如何对 HashSet 进行排序? 2022-01-01
- Java 中保存最后 N 个元素的大小受限队列 2022-01-01
- 由于对所需库 rt.jar 的限制,对类的访问限制? 2022-01-01
- 如何强制对超级方法进行多态调用? 2022-01-01
- 如何在不安装整个 WTP 包的情况下将 Tomcat 8 添加到 Eclipse Kepler 2022-01-01
- 如何使用 Stream 在集合中拆分奇数和偶数以及两者的总和 2022-01-01
- 在螺旋中写一个字符串 2022-01-01
- 首次使用 Hadoop,MapReduce Job 不运行 Reduce Phase 2022-01-01
- Spring Boot Freemarker从2.2.0升级失败 2022-01-01
- 如何使用 Eclipse 检查调试符号状态? 2022-01-01