Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: Texture Filters Issue

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2015
    Posts
    5

    Texture Filters Issue

    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)

    Code :
        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();
        }

  2. #2
    Senior Member OpenGL Lord
    Join Date
    May 2009
    Posts
    5,924
    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.

  3. #3
    Junior Member Newbie
    Join Date
    Apr 2015
    Posts
    5
    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?

  4. #4
    Senior Member OpenGL Lord
    Join Date
    May 2009
    Posts
    5,924
    Quote Originally Posted by MSmith View Post
    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).

  5. #5
    Member Regular Contributor
    Join Date
    Mar 2015
    Posts
    296
    Quote Originally Posted by Alfonse Reinheart View Post
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •