PDA

View Full Version : glAlphaFunc and glColor - doesn't this combine?



michelle
09-13-2010, 05:49 AM
I am trying to blend faces in a two pass approach. In the first pass, I only want to render fully opaque pixels with z-buffer writes enabled, and in the second pass, I only want to render non-fully-opaque pixels with z-buffer writes disabled.

So far, so good, if only glAlphaFunc did what I wanted it to do. When I render an RGBA texture that has some fully opaque pixels, some semi-transparent pixels and some fully transparent pixels, then the following combination does what I expect:

glEnable(GL_BLEND);
glEnable(GL_ALPHA_TEST);
glDepthMask(GL_TRUE);
glAlphaFunc(GL_EQUAL, 1.0f);

When I pass a texture with only fully opaque pixels and combine this with a GlColor command such as GlColor(1.0, 1.0, 1.0, 0.5), all pixels, semi-transparent now due to GlColor, will GET rendered, apparently bypassing GlAlphaFunc, even though I loaded the texture in RGBA mode.

Same for non-textured faces. Here, with GlColor(1.0,1.0,1.0,0.5), even though the face is semi-transparent now, the face DOES get rendered, apparently bypassing the GlAlphaFunc test, too.

Is this how GlAlphaFunc is supposed to work? Should it indeed ignore alpha contributions from GlColor and only work for the alpha inside textures?

thinks
09-13-2010, 06:47 AM
I suggest you take a look at glBlendFunc.

Alfonse Reinheart
09-13-2010, 09:52 AM
Is this how GlAlphaFunc is supposed to work? Should it indeed ignore alpha contributions from GlColor and only work for the alpha inside textures?

That depends: how do you generate your fragments?

The alpha test doesn't care what the texture color or glColor or whatever is. The alpha test only looks at the output fragment alpha value. This value depends entirely on what your fragment computation looks like.

Since you're using glColor, it sounds like you're using the fixed-function pipeline. So what is the glTexEnv set to? If it isn't set to multiply the texture color with the primary color, then nothing you set glColor to will matter at all.

To test this, just change the color to (0.5, 0.5, 0.5, 1.0). If the rendering image isn't darkened compared to normal, then your glTexEnv settings are wrong.


I suggest you take a look at glBlendFunc.

No. Unless he's actually using blending, he should disable GL_BLEND.