Android Question LibGDX SetBlendFuncSeparate

danijel

Active Member
Licensed User
Longtime User
I am using BlendFunction to draw sprites on surface like this.

B4X:
Sub Globals
    Dim GL as lgGL
    Dim Batch as lgSpriteBatch
    Dim Wheel As lgSprite
End Sub
'
'
'
Sub LG_Render
   Batch.Begin   
   Batch.SetBlendFunction(GL.GL20_SRC_ALPHA, GL.GL20_ONE_MINUS_SRC_ALPHA)
   Wheel.Draw(Batch)
   Batch.End
End Sub


However, I need something like this:
B4X:
Batch.Begin   
    'GL.glBlendFuncSeparate(GL.GL20_SRC_ALPHA, GL.GL20_ONE_MINUS_SRC_ALPHA, _
    '                       GL.GL20_ZERO,      GL.GL20_ONE)
Wheel.Draw(Batch)
Batch.End

but Batch.SetBlendFuncSeparate function don't exist.
I found GL.glBlendFuncSeparate() but I don't know how to tell Batch (lgSpriteBatch) to use it...

Thank you
 

Informatix

Expert
Licensed User
Longtime User
I am using BlendFunction to draw sprites on surface like this.

B4X:
Sub Globals
    Dim GL as lgGL
    Dim Batch as lgSpriteBatch
    Dim Wheel As lgSprite
End Sub
'
'
'
Sub LG_Render
   Batch.Begin  
   Batch.SetBlendFunction(GL.GL20_SRC_ALPHA, GL.GL20_ONE_MINUS_SRC_ALPHA)
   Wheel.Draw(Batch)
   Batch.End
End Sub


However, I need something like this:
B4X:
Batch.Begin  
    '

Wheel.Draw(Batch)
Batch.End

but Batch.SetBlendFuncSeparate function don't exist.
I found GL.glBlendFuncSeparate() but I don't know how to tell Batch (lgSpriteBatch) to use it...

Thank you
The first thing to try would be:
B4X:
GL.glEnable(GL.GL20_BLEND)
GL.glBlendFuncSeparate(GL.GL20_SRC_ALPHA, GL.GL20_ONE_MINUS_SRC_ALPHA, GL.GL20_ZERO, GL.GL20_ONE)
before Batch.Begin.
 
Upvote 0

danijel

Active Member
Licensed User
Longtime User
First of all, thank you very much Informatix for getting into this.

Unfortunately, I can't get BlendFuncSeparate working. Whatever functions I type result is always the same.
So I guess this way of setting BlendFunction is simply ignored.

I made an Example project.
What I want to achieve is to set 3 sprites one onto another like in photoshop with layers:

expected.jpg


1st sprite = Blue opaque circle (png1.png)
2nd sprite = Android (png2.png)
3rd sprite = White semitransparent circle on top (png3.png)


What I get in example is transparency leaking even though blue circle is drawn first and 100% opaque.

B4a_result.jpg


So i think I can solve this with separate blend function and tell him to blend colors and put alpha to 1.0

Is there a way to achieve "photoshop result" with stacking sprites ?
 

Attachments

  • LibGDXExample2.zip
    223.2 KB · Views: 231
Upvote 0

Informatix

Expert
Licensed User
Longtime User
You forgot to mention a very important thing:
Surface = LGDX.InitializeTransparentView(Config, "LG")

In this case, the blending management is a bit complicated (the sprites are drawn as expected, then the whole surface is blended with the activity background). You should avoid using a transparent view if there's not a strong reason.
 
Upvote 0

danijel

Active Member
Licensed User
Longtime User
I'll try to avoid TransparentView in the future.
For this time I solved it with additional black bitmap between activity background and LGDX Surface so background is not visible.
 
Upvote 0
Top