PDA

View Full Version : TBGL-Drawing Alpha 2D



ReneMiner
21-02-2013, 17:33
I want to create some boxes in front of my TBGL-Screen where some numbers shall be displayed on. I have set



TBGL_UseAlphaTest(%TRUE)
TBGL_AlphaFunc(%TBGL_GREATER, 0.5)


and use a TBGL_Color with a little more than 160 alpha to draw the box translucent. But it is full opaque till down to alpha 128
If I use 127 the box appears totally transparent (is invisible)
How can I setup to draw the box to appear translucent?

What have I overseen this time?

Petr Schreiber
21-02-2013, 18:33
Hi Rene,

you were close :)

There are two alpha related operations in TBGL - alpha testing and alpha blending.

Alpha testing does what you experienced. It tests the alpha of incoming fragment (pixel) and based on its value it makes it solid or invisible. Nothing in between.

Alpha blending on the other side allows to use the full scale of transparency, and does what you need - based on alpha value, it blends the incoming fragment color with existing, creating the nice illusion of transparency.

To enable alpha blending, you need to enable blending as a such, and setup the blending function accordingly. Here little sample:


TBGL_UseBlend TRUE
TBGL_BlendFunc %GL_SRC_ALPHA, %GL_ONE_MINUS_SRC_ALPHA

' -- Render the transparent stuff here


Or, maybe better you could use the state preserving approach to avoid state leaks:


TBGL_PushBlendFunc %GL_SRC_ALPHA, %GL_ONE_MINUS_SRC_ALPHA
TBGL_PushState %TBGL_BLEND

' -- Render the transparent stuff here

TBGL_PopState
TBGL_PopBlendFunc



Petr

ReneMiner
21-02-2013, 18:41
Yeah, that's cool :)
Works better than expected, I see a whole lot of new possibilities now. Great!