libgdx texture filters and mipmap

Kenkron picture Kenkron · Mar 13, 2013 · Viewed 14.8k times · Source

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

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.

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:

This code will show a linear filter for minified images:

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

whlie this code will not:

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

which seems opposite to the libGDX function:

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

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.

This code causes nothing to display

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

This code displays, but with nearest filtering

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

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.

Answer

twiz picture twiz · Aug 5, 2014

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.

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

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