How to disable blending for Texture?

Anything libgdx related goes here!

How to disable blending for Texture?

Postby toba » Tue May 14, 2019 3:09 pm

What i'm trying to do? I got a Texture which in its part has let's say red rectangle and all remaining its pixels are fully transparent. To remove red rectangle i draw on it a Pixmap which is filled with fully transparent pixels. I'm expecting that Pixmap overwrites red rectangle and whole texture will be fully transparent. But rectangle remains. I guess it's caused by blending which is enable by default for Texture.

Code: Select all
private void removeRedRectangleFromTexture(Texture dstTexture)
{
   Pixmap pixmapTransparentPatch = new Pixmap(40, 20, Format.RGBA8888);
   dstTexture.draw(pixmapTransparentPatch, 100, 50);
}


I know that i could use something like this code below. But real Texture i'm using in my project is 3800x3800 and there are other things drawn.

Code: Select all
private void removeRedRectangleFromTexture(Texture dstTexture, Pixmap pixmapDstTextureMirror)
{
   Pixmap pixmapTransparentPatch = new Pixmap(40, 20, Format.RGBA8888);
   Pixmap.setBlending(Blending.None);
   pixmapDstTextureMirror.drawPixmap(pixmapTransparentPatch, 100, 50);
   Pixmap.setBlending(Blending.SourceOver);
   dstTexture.draw(pixmapDstTextureMirror, 100, 50);
}


Is it possible to do it directly on Texture?
toba
 
Posts: 5
Joined: Wed Jan 17, 2018 8:48 pm

Re: How to disable blending for Texture?

Postby shatterblast » Wed May 15, 2019 4:18 am

toba wrote:What i'm trying to do? I got a Texture which in its part has let's say red rectangle and all remaining its pixels are fully transparent. To remove red rectangle i draw on it a Pixmap which is filled with fully transparent pixels. I'm expecting that Pixmap overwrites red rectangle and whole texture will be fully transparent. But rectangle remains. I guess it's caused by blending which is enable by default for Texture.

I do not think normal use of a SpriteBatch would perform what you seek, though a possibility exists that some magical method belonging to a specific class somewhere out there in LibGDX land allows it. Rather instead, I point you towards Frame Buffer Objects. While I do not currently work with them, I believe drawing to an FBO acts like working with only a single layer of drawing software, like Krita or Photoshop, if that helps you understand their general concept. I think using a SpriteBatch works more closely to the idea of painting on multiple layers, giving each Texture or Sprite its effective ownership of an individual layer. Calling the end() method on a SpriteBatch slaps them all together, so you would not get the transparency effect you want that an FBO's single layer hopefully offers. Just to go a bit off topic, though, I think a SpriteBatch can possibly feed into an FBO for whatever reason. Something like that might prove useful for painting on the surfaces of 3D objects, like "water" or "sky" for example, if that ever serves you.

https://github.com/mattdesl/lwjgl-basics/wiki/FrameBufferObjects
shatterblast
 
Posts: 404
Joined: Sun Jul 06, 2014 1:14 pm


Return to Libgdx

Who is online

Users browsing this forum: Google [Bot] and 1 guest