Android Question LIBGDX blending problem

RichyK68

Active Member
Licensed User
Hi,

I'm trying to work out why the masking technique below doesn't work. I have a mask that is drawn to the whole screen, the left 50% of the screen is completely transparent (rgba=0) and the right 50% is completely white (rgba=1).

I then draw a texture in the center of the screen so it overlaps both sides of the mask. I expect to see only the half of the texture that overlaps the white area. The part of the texture that overlaps the black area shouldn't be drawn.

B4X:
' completely clear out values in buffer, as I rely upon Alpha channel

GL.glClearcolor(0,0,0,0) 
GL.glClear(GL.GL10_COLOR_BUFFER_BIT)

Batch.Begin

GL.glColorMask(False, False, False, True)

' Mask is 100% blank (transparent,alpha=0) on left 50% of screen and 100% white on right 50% of screen (alpha=1)
Batch.SetBlendFunction(GL.GL10_ONE, GL.GL10_ZERO)
Batch.DrawTex2(Mask, 0, 0, vpW, vpH)

Batch.End

' now draw my texture, expecting to only see the right half of the texture,
' because the alpha should equal 0 on the left of the screen and 1 on the right,
' so I expect the left of the screen to be masked
Batch.SetBlendFunction(GL.GL10_DST_ALPHA, GL.GL10_ZERO)
Batch,Begin
Batch.DrawRegion3(MyTextureRegion, vpW * 0.5f - MyTexture.Width * 0.1f, vpH * 0.5f - MyTexture.Height * 0.1f, MyTexture.Width * 0.1f, MyTexture.Height * 0.1f, _
                  MyTexture.Width * 0.2f, MyTexture.Height * 0.2f, 1.0f, 1.0f, CarAngle) 

Batch.End
Unfortunately I see the whole texture. Can anybody tell me what I am doing wrong?

Thanks,

Richard
 
Top