PDA

View Full Version : Texture Filters Issue



MSmith
04-13-2015, 03:22 PM
Hi folks,

Making an Android app. Whenever I set GL10.GL_TEXTURE_MIN_FILTER to GL_LINEAR_MIPMAP_NEAREST and GL_TEXTURE_MAG_FILTER to GL_LINEAR my textures disappear and only a white cube is generated in it's place. Same if I don't set them and use the default values. But if both are either GL_LINEAR or GL_NEAREST (or a combination of the two) it works fine.

This is my code...any advice? Below works, but not if I change GL10.GL_TEXTURE_MIN_FILTER to GL_LINEAR_MIPMAP_NEAREST. (Note: I tried both methods shown below of loading the bitmap with the same results)


public void loadTexture(GL10 gl, Context context) {
gl.glGenTextures(1, textureIDs, 0);

// final BitmapFactory.Options options = new BitmapFactory.Options();
// options.inScaled = false;
// final Bitmap bitmap = BitmapFactory.decodeResource(context.getResources( ), R.drawable.myTexture, options);

InputStream is = context.getResources().openRawResource(R.drawable. myTexture);
Bitmap bitmap;
try {
bitmap = BitmapFactory.decodeStream(is);
} finally {
try {
is.close();
} catch(IOException e) {
}
}

gl.glBindTexture(GL10.GL_TEXTURE_2D, textureIDs[0]);

gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);


GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);


bitmap.recycle();
}

Alfonse Reinheart
04-13-2015, 03:40 PM
GL_LINEAR_MIPMAP_NEAREST is only appropriate for a texture if it has mipmaps. If it doesn't have mipmaps, you shouldn't use mipmap filtering, and your texture doesn't use mipmaps.

MSmith
04-13-2015, 07:51 PM
Ahh...Ok. Thank you! I haven't touched openGl in 10+ years (since school) so I have to go back and remind myself of few topics...including mipmaps apparently ;)

I've read the difference of Linear vs Nearest, but I'm trying to understand the affects better. Is one less pixelated but better performance?

Alfonse Reinheart
04-13-2015, 09:49 PM
I've read the difference of Linear vs Nearest, but I'm trying to understand the affects better. Is one less pixelated but better performance?

You should not use NEAREST because you think it will help in performance. Most, if not all, rendering hardware is designed around LINEAR filtering, so using NEAREST will generally buy you nothing. You should use NEAREST because you want what it provides in terms of texture sampling (ie: exact texel values with no blending between neighboring texels).

reader1
04-15-2015, 08:50 AM
You should not use NEAREST because you think it will help in performance. Most, if not all, rendering hardware is designed around LINEAR filtering, so using NEAREST will generally buy you nothing. You should use NEAREST because you want what it provides in terms of texture sampling (ie: exact texel values with no blending between neighboring texels).
it's not you should not or should. that depends on the goal you will precess. different algorithm results in different effect. texture mapping is a complex work, need differnt ways to do. then you can get a perfect effect.