Visit us on Google Play 

Twitter Gplus E-mail RSS

Fixing Bleeding in LibGdx’s TextureAtlas

flattr this!

This is a small post for a small problem. When using a texture atlas, bleeding might occur. Meaning that a region from the atlas might show half a pixel from bordering textures. It seems a common problem. When googling it, you find a lot of general OpenGL advice: Inset the region about half a pixel (like here). Sounds easy, but it took me a while to find the solution for LibGDX. Here it is, a simple utility function. Apply it on each region that troubles you, and the bleeding should disappear.

public static void fixBleeding(TextureRegion region) {
	float x = region.getRegionX();
	float y = region.getRegionY();
	float width = region.getRegionWidth();
	float height = region.getRegionHeight();
	float invTexWidth = 1f / region.getTexture().getWidth();
	float invTexHeight = 1f / region.getTexture().getHeight();
	region.setRegion((x + .5f) * invTexWidth, (y+.5f) * invTexHeight, (x + width - .5f) * invTexWidth, (y + height - .5f) * invTexHeight);       



Leave a Reply

− 5 = three

Home Programming Fixing Bleeding in LibGdx’s TextureAtlas