Android OpenGL - ES Texture bleeding

≯℡__Kan透↙ 提交于 2019-12-04 08:27:17

Well, after speaking to a friend I managed to solve this little problem.

It turns out that if you wish to have exact pixel perfect textures you have to specify the edge of the texture to be halfway into the pixel.

To do this I simply added half a pixel or subtracted half a pixel to the measurement for the texture coords.

Like so:

//Top Left
            textureCoords[textPlace] = xAdjust*currentAtlas.texSpaceWidth + currentAtlas.halfPixelAdjust;        textPlace++;
            textureCoords[textPlace] = (yAdjust+1)*currentAtlas.texSpaceHeight - currentAtlas.halfPixelAdjust;    textPlace++;

This was simply calculated when loading the texture atlas:

(float)(0.5 * ((1.0f / numberOfTilesInAtlasRow) / pixelsPerTile));

Although if the height was different to the width of each tile (which could happen) you would need to calculate them individually.

This has solved all the artifacts so I can continue on. Hope it helps someone else!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!