I am developing a game on android using OpenGL ES 1.0 for Android OS. It is a 2d game using a simple Orthographic projection and textures for the sprites. One of these textures has a small line (it looks like 1 pixel) all the way across the top that has the same colors as the bottom 1-pixel line of the texture. It is almost as if the bottom line of the image raster was copied and pasted as the top line as well.

Is anyone familiar with this type of error? What could the problem be?

  • \$\begingroup\$ Could you post a screenshot and the actual texture ? Maybe the part of the code that displays the texture correctly and incorrectly could be useful too. \$\endgroup\$ – Heckel May 28 '14 at 12:27

When this happens in my experience it's usually due to a combination of using texture wrapping/repeat and bilinear filtering. The bilinear filtering can sometimes sample from coordinates outside the 0-1 range and because it's set to repeat it will sample pixels from the other side of the image. Try using GL_CLAMP_TO_EDGE (example of usage) to confirm this is the case.

There's a few different ways to fix it:

  • Don't use wrapping
  • Don't use bilinear filtering
  • Add a row of transparent pixels at the bottom of the image.
  • 1
    \$\begingroup\$ Technically the problem is that the [0,1] coordinate range itself is flawed. Interpolation pulls image data from the 4 nearest texels (possibly more if anisotropic filtering is enabled) and then averages them based on the distance of the center of each texel from the sample location. 0.0 is not a texel center, that is the boundary of the texture, so it is equa-distant from the texel to its right and its left. GL_CLAMP_TO_EDGE fixes that by clamping coordinates to a more restrictive range than [0,1], such that the smallest and largest coordinates are exactly the center of a texel. \$\endgroup\$ – Andon M. Coleman May 29 '14 at 23:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.