PDA

View Full Version : Textures with transparency



ogle234
12-15-2005, 07:33 AM
Hi
I need help with blending textures e.g - draw an airplane and then put an insignia on its wing -
say a cross.

I am doing the following in the WGL/OpenGL environment

1) create a bitmap using createDIBSection with an alpha channel
2) clear it with black and alpha =0
3) draw the red cross to it with alpha = 1
4) make a texture out of it using GL_RGBA, GL_UNSIGNED_BYTE
5) put this texture on the screen using GL_DECAL

It doesn't work - instead it pastes the texture with the last colour drawn to screen!
so say I drew a yellow object last and then draw this texture
on the wing - I just see a yellow square.

If I use GL_REPLACE I get a wing with a black square & red cross inside it. - NOT what I want.

The way red book describes DECAL -is that is GL_RGBA is used then

" C = Cf(1-At) + CtAt, A = Af
a subscript of t indicates a texture value,
f indicates the incoming fragment value,
and no subscript indicates the final, computed value"

I have checked that the bitmap that I create and the screen are both capable and correctly
hold alpha information.

what am I doing wrong?!!

stuckontexture

memfr0b
12-16-2005, 12:27 AM
" C = Cf(1-At) + CtAt, A = Af
a subscript of t indicates a texture value,
f indicates the incoming fragment value,
and no subscript indicates the final, computed value"
Cf is the color of the incoming fragment, not the value already stored in the color buffer. The texture stage has no access to the contents of the framebuffer. If the object you're drawing would be yellow without a texture, the texture will be decal'ed on a yellow surface.

If you want to blend a texture over something that's already stored in the framebuffer, you need GL_BLEND.

Set the texture environment mode to GL_REPLACE and glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA).

ogle234
12-16-2005, 02:16 AM
Yes your suggestion works. thanks a ton!

But :
I dont understand what 'incoming fragment' is? Firstly 'fragment square' according to the red book (pg 13) - is 'a pixel in the frame buffer'. if this is not what 'incoming fragment' refers to - what is it?

memfr0b
12-16-2005, 02:41 AM
"Incoming fragment", or short "fragment", refers to the output of the rasterizer and the following stages, before the data is written to the framebuffer. The fragement square is simply the area, the fragment will occupy once it has been written to the framebuffer.

A pixel on the other hand, is a set of bits (color, depth, alpha, stencil, etc) in the framebuffer. When a fragment reaches the framebuffer (ie it isn't discarded by one of the fragment tests), it modifies some or all bits of its fragment square, either by replacing them with its own values (depth write, non-blended color), or by merging the bits according to some function (color blending, stencil function).