Home Ask Login Register

Developers Planet

Your answer is one click away!

aboud aladdin February 2016

libgdx Nearest texture filtering is forced?

hi i am making a simple import from blender and i have a problem in texture filtering. the texture appears to be filtered by nearest min filter nearest min filter , linear mag filter issue but questioning its texture description attribute says its linear. also setting it to linear filtering doesnot change the situation

enter image description here http://s10.postimg.org/wgmxoz5fd/issue.png


Tenfour04 February 2016

I don't think LibGDX has methods available for turning on anisotropic filtering, but you can try this helper class. Aniostropic filtering is not guaranteed to be supported by OpenGL ES, so it has to check for availability. I haven't tested this with LibGDX in the past year, so I'm not positive it still works correctly.

public class Anisotropy {

    private static boolean anisotropySupported = false;
    private static boolean checkComplete = false;
    private static float maxAnisotropySupported = 1.0f;

    /**Applies the given anisotropic level to the texture. Returns the anisotropy value that was applied, 
     * based on device's maximum capability.
     * @param texture The texture to apply anisotropy to.
     * @param anisotropy The anisotropic level to apply. (Will be reduced if device capability is less.)
     * @return The anisotropic level that was applied, or -1.0 if anisotropy is not supported by the device.
    public static float setTextureAnisotropy(Texture texture, float anisotropy){
        if (isSupported()) {
            float valueApplied = Math.min(maxAnisotropySupported, anisotropy);
            Gdx.gl20.glTexParameterf(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_MAX_ANISOTROPY_EXT, valueApplied);
            return valueApplied;
        } else {
            return -1f;

    public static boolean isSupported(){
        if (!checkComplete){
            GL20 gl = Gdx.gl;
            if (gl != null){
                if (Gdx.graphics.supportsExtension("GL_EXT_texture_filter_anisotropic")){
                    anisotropySupported = true;
                    FloatBuffer buffer = BufferUtils.newFloatBuffer(16);
                    Gdx.gl20.glGetFloatv(GL20.GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, buffer);
                    maxAnisotropySupported = buffer.get(0);
                checkComplete = true;
            } else 
                throw new UnsupportedOperationException 

Post Status

Asked in February 2016
Viewed 3,123 times
Voted 13
Answered 1 times


Leave an answer

Quote of the day: live life