PDA

View Full Version : an intersting problem about blend...



wusheng
09-29-2004, 06:35 AM
when i use glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);t o 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!

mrbill
09-29-2004, 07:09 AM
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

rgpc
09-29-2004, 06:56 PM
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).

Tom Nuydens
09-29-2004, 11:50 PM
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

rgpc
09-30-2004, 12:32 AM
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.

V-man
09-30-2004, 05:56 AM
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.

Relic
09-30-2004, 06:02 AM
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.

wusheng
09-30-2004, 06:47 AM
thank you!rgpc and mrbill.your advices help me a lot...