PDA

View Full Version : doubt in blending



infinitecmdz
03-13-2004, 09:33 PM
hi,
i'm a newbie in Opengl and i have a doubt in blending. please tell if the procedure i follow is correct for blending. first i draw all the opaque objects and then in the last i draw the object to be transparent. I'm using GLUI for interface. so i have to check the state of the checkbox and enable and disable the blending. hence just before draw the transparent object (and after drawing the opaque objects), i check the state of the checkbox and enable blending.

here is the piece of code doing that:

if(blend)
{
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4f(1.0f,1.0f,1.0f,0.5f);
glEnable(GL_BLEND);
glDepthMask(GL_FALSE);
}
else
{
glBlendFunc(GL_ONE, GL_ZERO);
glColor4f(1.0f,1.0f,1.0f,0.0f);
glDisable(GL_BLEND);
glDepthMask(GL_TRUE);
}

now heres the problem, in the output, i see a additional black inner object(the one which is opaque).this black object is stationary.so when i rotate the object when in blend mode, the black object interferes with the rotating opaque object.

I hope you understand what i mean. i think there must be something wrong in specifying the source and destination factors in glBlendFunc(). please tell me the error.

thanx

ZbuffeR
03-14-2004, 02:22 AM
It seems globally corect.
But the change in glBlendFunc is not useful : leave it to src_alpha etc, if blending is disabled, blendFunc is not used.

One thing though : your transparent objects have to be drawn from back to front. Yes, it is a pain is the neck.
And why your alpha color is 0.5 ? why not 1.0 ?

For the problem with you 'black object', well I do not quite understand what you mean. You may draw it 2 times ?


Hope it helps.

infinitecmdz
03-14-2004, 08:57 AM
hi,

actually, i kept the alpha value 0.5 to make the object appear transparent.

as for the black object, i tried glDepthMask(GL_TRUE) and it worked. the wierd black object just disappered. but how is this possible?

i just don't understand. the glDepthMask() must be set to false so that the buffer is read only when rendering transparent objects. but if i keep it to false, i get that misterious black inner object(which is duplicate of the lit inner object). I just tried and kepth the glDepthMask to true and it worked out perfectly.

how is this possible??

ZbuffeR
03-14-2004, 10:40 AM
.... but how is this possible?
Well, I don't know, you did not put your code or a screenshot to explain your 'black ghost' better, so...

For substractive transparency (your case), you do have to sort objects from back to front. Depth write should not be useful, but can limit sorting 'bugs'.

If you just need additive transparency, it is much easier, no need to pre-depth-sort your transparent polys. Use ONE ONE for blendfunc.

infinitecmdz
03-14-2004, 01:09 PM
hi,

sorry for not sending a pic.

here are the urls.i have to pics to make clear of what i'm saying:
http://www.villagephotos.com/viewpubimage.asp?id_=8245991

and
http://www.villagephotos.com/viewpubimage.asp?id_=8246074

thanx

infinitecmdz
03-14-2004, 01:14 PM
hi,

i forgot to ask you something in the earlier post. what is subtractive and additive transparency? also is there some good resource on the net on blending? i'm particularly confused on how the source and destination factors in glBlendFunc() work.

thanx

JanHH
03-15-2004, 07:56 AM
in general, everything is right. if you first draw all solid faces with blending disablend and after that draw all transparent faces in back-to-front order with blending enabled, it should look fine. the black stuff rather looks like a culling problem.