Masking an alpha-containing image makes the inner mask black

I am trying to mask a background image that is smaller than a mask. and the space between the background and the mask turns black.

mask and background

enter image description here

This is the code I'm using:

batch.end(); batch.begin(); Gdx.gl20.glColorMask(false, false, false, true); batch.setBlendFunction(GL20.GL_ONE, GL20.GL_ZERO); batch.draw(mask, getX(), getY()); batch.flush(); Gdx.gl20.glColorMask(true, true, true, true); batch.setBlendFunction(GL20.GL_DST_ALPHA, GL20.GL_ONE_MINUS_DST_ALPHA); batch.draw(texture, getX(), getY()); batch.flush(); batch.setBlendFunction(GL20.GL_SRC_ALPHA,GL20.GL_ONE_MINUS_SRC_ALPHA); batch.end(); batch.begin(); 

I tried all kinds of combinations of functions without any success. maybe I missed something.

Update

Attaching a graph in which I build all the possible (relevant) results of the src and dst mixing functions. Fortunately, none of the below works, and, as I already guessed, you need to do something else to achieve the result.

  Gdx.gl20.glColorMask(true, true, true, true); batch.setBlendFunction(src_func, dst_func); batch.draw(texture, getX(), getY()); 

enter image description here

+7
opengl libgdx
source share
2 answers

Decided to use FrameBuffer.

  batch.end(); spriteBatch.begin(); buffer.begin(); Gdx.gl20.glColorMask(false, false, false, true); spriteBatch.setBlendFunction(GL20.GL_ONE, GL20.GL_ZERO); spriteBatch.draw(mask, 0,0); Gdx.gl20.glColorMask(true, true, true, true); spriteBatch.setBlendFunction(GL20.GL_DST_ALPHA, GL20.GL_ZERO); spriteBatch.draw(texture, 0,0); spriteBatch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); buffer.end(); spriteBatch.end(); batch.begin(); batch.draw(buffer.getColorBufferTexture(), getX(), getY()); 
+3
source share

Just by looking at your images, it looks like this:

  • Alpha masks fully control output alpha
  • You want the alpha background image to be taken into account as well.

In other words, you only need alpha, where both images have alpha.


I have not yet been able to learn additional mixing functions and their work, as well as update information on how to achieve my goals, as I understand it, but perhaps knowing what you are trying to do will help you understand this before I get to it .

How to make mixing in LibGDX - this question seems interesting, combining source and target images in a grid to show effects.

0
source share

All Articles