Transparency without blending

Is it possible to have transparent textures without any blending? If I use BLEND_ZERO as blend function, it appears that the pixels that should normally be blended gets black.

What I want to do is a text label with transparent background and to make the text as clear as possible I don’t want it to blend with the background.

Björn

Yes, it’s possible by using an alpha transparent texture: RGBA format. Additional to your text image (for example 24 bpp PNG) you have a same sized “mask” alpha layer (8 bpp, grey): all the fully transparent parts you set to 0, the opaque parts to 255.
You could merge this images manually at runtime, or via pixel editors at dev time, to a nice 32 bpp PNG file in RGBA format.

Then you feed this to Xith3d in the usual way, so for the TextureLoader you say “RGBA” instead of “RGB”, and enable blending for the Appearance (ie TransparencyAttributes(), which setMode to BLENDED).

Should work well (it does for me).
If I remember correctly my OpenGL Redbook, there’s also a way to directly say that colour X (0 in your case) has to be transparent? However I don’t remember if’s that correct and how to do…

I create an empty(transparent) BufferedImage and paint(black) letters directly on to it, but when it is rendered the edges becomes blurry as it is blended against the background. If I use BLEND_ZERO, the pixels that were blended becomes black, thereby swelling the letters, making them harder to read.

Do you get any of the above effects?

Björn

Hi,

[quote]If I use BLEND_ZERO as blend function, it appears that the pixels that should normally be blended gets black.
[/quote]
This is correct behavior. BLEND_ZERO tells that system should use zeros instead the actual values of src/dst fragment, which result in black color (R=G=B=0).

The effect you get is because of texture magnification/minification filter.

Use minification and magnification filter as BASE_LEVEL_POINT and use normal (default) blending mode.

Yuri

Thanks a lot!

Björn

[quote]Hi,
This is correct behavior. BLEND_ZERO tells that system should use zeros instead the actual values of src/dst fragment, which result in black color (R=G=B=0).
[/quote]
Does this mean for example setDstBlendFunction(BLEND_ZERO) is this a special function?

Because when I read the Java3d doc it says:

So what I thought was this: setting DstBlendFunction to BLEND_ZERO would mean: f = 0 instead of f = (1-alpasrc). So … + f*dst would result in ignoring the dst colour entirely: so the source would be always painted without transparency…

However, what happens with an RGBA texture in the reality is this: “somehow” using DstBlendFunction with BLEND_ZERO does “just” paint the src pixels which have got an Alphamask > 0 and then without blending, ie it looks sharp like the original poster asked for.
This is handy, but I don’t understand the documentation then…

PS: Would it be possible to use a treshold in that DstBlendFunction BLEND_ZERO? So instead of Alphamask > 0 something like: Alphamask > X ?

[quote]so the source would be always painted without transparency…
[/quote]
Yes, and depending on SRC blend function, if you set it to BLEND_ONE, then fragment will be painted as it is, otherwise you will get kind of darkening of source fragment (BLEND_SRC_ALPHA is default, and alpha is in [0, 1]).

[quote]However, what happens with an RGBA texture in the reality is this: “somehow” using DstBlendFunction with BLEND_ZERO does “just” paint the src pixels which have got an Alphamask > 0 and then without blending, ie it looks sharp like the original poster asked for.
[/quote]
Because of SRC alpha in texture is discrete and has values of either 0 or 1, not in between (this is my guess). And, possible, alpha test is also doing something.

[quote]Would it be possible to use a treshold in that DstBlendFunction BLEND_ZERO? So instead of Alphamask > 0 something like: Alphamask > X ?
[/quote]
Try something like:

setAlphaTestFunction(GREATER);
setAlphaTestValue(X);

Yuri