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

查看:35
本文介绍了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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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