3
votes

I am using a power of two sized texture (128x128) and I am drawing small portions of it onto polygons (using it as a texture atlas). I have set the following:

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

However the result is a texture that is still blurred together. It looks like it's using GL_LINEAR instead.

Any ideas why the texture would still be coming out blurry instead of pixelated?

Here is an example:

Letter drawn with four different texture resolutions

The letter F is a portion of the image. Here it is drawn using a 128px image, 256px, 512px, and 1024px. As you can see it gets better, but even at 1024px it still blends the edges a little. I should be able to use a 128px image and scale it up using GL_NEAREST and have it have clear edges. What could be causing it to draw like this?

EDIT

I have updated the app to use GLES20 and am still having the issue. I have tried using the following after binding the texture and before the call to drawArrays just to make sure I was using GL_NEAREST:

GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);

EDIT 2

The problem happens even without using an atlas. I put an 8px by 8px png on a quad and it was a blurry mess. Would there be some reason OpenGL ES 2.0 is not using GL_NEAREST?

Here is the result:

8px by 8px letter A drawn on quad

2

2 Answers

1
votes

I believe glTexParameterf should be glTexParameteri. You're passing enums as the final argument, not floats.

Are you checking for errors with glGetError as well?

Also make sure that you're setting it for each texture you want to have linear sampling. It's state is per texture, not global.

1
votes

I finally figured it out!!!!

It was the way I was loading my resource.

I changed from this:

Bitmap bitmap = BitmapFactory.decodeResource(GLRenderer.context.getResources(), textureId);

to this:

InputStream is = GLRenderer.context.getResources().openRawResource(textureId);
Bitmap bitmap;
try {
    bitmap = BitmapFactory.decodeStream(is);
} finally {
    try {
        is.close();
    } catch(IOException e) {
        // Ignore.
    }
}