1

I am using OpenGL ES 2.0 ing iOS and I found when I add texture with different size and some of them get blurred, some disappeared. I used mipmap but it doesn't work.

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);    
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageData);
glGenerateMipmap(GL_TEXTURE_2D);

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
Dilnar
  • 59
  • 2
  • *"some of them get blurred"* - Of course, if a texture is minified (the texture is greater than the area where it is drawn on), then the color of some adjacent pixels has to be mixed and drawn on a single fragment. That's what [mipmapping](https://en.wikipedia.org/wiki/Mipmap) does. – Rabbid76 Aug 28 '19 at 04:47
  • Ify you turn off mipmapping they won't be blurred, but they'll be jagged or "sparkly". – user253751 Aug 28 '19 at 05:14

1 Answers1

2

some of them get blurred

Some blur is inevitable.

Mipmapping is simply downscaling and that is effectively 4-to-1 averaging filter which will inevitably reduce high frequency information).

You're probably also using bilinear filtering. Pixels don't exactly align with texels, so you grab the 4 nearest texels and perform a weighted sum on those. Yet more blur ...

It's worth noting that the built-in mipmap generation normally uses a very simple box filter to downscale the mipmaps. You can often fine tune the sharpness of the result with other downsampling algorithms, but you need to generate the mipmaps manually offline if you want to try that.

some disappeared.

The clipping on the edges of the faces is usually a sign that your texture is "too tight" to the edge of the geometry, so the blur effect is effectively hitting the edge of the triangle and clipping.

Ensure that you have a small ring of transparent texels around the edge of the on-screen rendering of each icon (even when rendered at the smallest mipmap level). If it is still clipping make that buffer region larger.

solidpixel
  • 10,688
  • 1
  • 20
  • 33