an intersting problem about blend...

when i use glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);to blend an fragment with the framebuffer,
the program operates well…
however, if we replace the “glBlendFunc (GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);”
with"glBlendFunc (GL_ONE_MINUS_DST_ALPHA,GL_DST_ALPHA);"
nothing can be seen…
why???
I have tried many times in many different environments, but the result…
in fact, the SRC_ALPHA and the DST_ALPHA are both between 0–1.
i am puzzled…
can someone help me?
thanks!

Originally posted by wusheng:

however, if we replace the “glBlendFunc (GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);”
with"glBlendFunc (GL_ONE_MINUS_DST_ALPHA,GL_DST_ALPHA);"
nothing can be seen…
why???

Two most common reasons:

First:

Make sure your color buffer has a destination alpha. ( Do a glGetIntegerv( GL_ALPHA_BITS, &i ); )

If you have 0 bits of alpha, the destination alpha is taken to be 1.0 always, which effectively turns your blend into glBlendFunc( GL_ZERO, GL_ONE );

If you have 0 bits of alpha, review your initialization code to make sure you are correctly asking for the pfd/xid you really want.

Second:

Make sure you clear the color buffer correctly.
If you clear the destination alpha to 1.0, your blend will always leave the destination alone.

-mr. bill

If you are rendering to a window, under Windoze, then your destination alpha will always (?) be 1.0.

So you are essentially telling GL that you always want to write 0 to the framebuffer (Src * 1 - 1) + (Dst * 0).

Originally posted by rgpc:
If you are rendering to a window, under Windoze, then your destination alpha will always (?) be 1.0.
What on earth gave you that idea?

– Tom

Having used glCopyTexSubImage2D() to use data from the frame buffer and then not being able to blend it correctly because it didn’t have alpha (or rather it had alpha of 1.0). The result was the areas that should have been transparent were not transparent.

It’s seems I was wrong though as I just tested it with the code that experienced the problem and it didn’t happen. So ignore my earlier post.

rgpc, I think you are thinking about the front buffer. The back buffer will support alpha.

On Windows, you have to explicity ask for an alpha channel when you create a 32 bit surface.

With GLUT, I think you have to pass GLUT_ALPHA to the CreateWindow function.

It’s kind of stupid if you ask me.

Guys, if you have not allocated a destination alpha channel, any readback of alpha will return 1.0 for alpha.
If you have a destination alpha channel in your pixelformat, then front AND back buffer will have it.

thank you!rgpc and mrbill.your advices help me a lot…