Blending

I am experiencing a problem with blending. I am rendering two objects that occupy the same space (i.e. exactly the same x, y and z coords) but when blending is turned on for rendering the second object, I cannot see any of the first object.

If I only render one of the objects using blending then I can see through it…does anyone know why I may be having a problem??

I have also tried moving the first object so that the second is now above, but again blending has no effect.

Thanks,
Steve

Try this

glDisable(GL_BLEND);
glDepthFunc(GL_LESS);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

…draw first pass…

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_COLOR, GL_DST_COLOR);
glDepthFunc(GL_LEQUAL);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

…draw second pass…

repeat…

It doesn’t matter if the first or second object is near or far from the viewer where only two objects in the scene but the alpha component.

for two objects in the scene, try to eneble blending and then render first the opaque object, then the translucence one. it’s should work.

I have tried what has been suggested, with no success as of yet ! :frowning:

I may have found where the problem lies. If I zoom out of the scene far enough, the objects start to disappear. Before you say that it has reached the far clipping plane IT HASN’T, It is being obscured by what appears to be a silhoutted version of the objects themselves.!!?!?!?!?

I`m not sure if Ive explained this well, but if anyone understands what I have said I would be greatful for any hints as to what might be going wrong.

Thanks,
Steve

You do clear the depth buffer do you?

-Lev

At the start of the render_scene() function I call :

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	

I still haven’t managed to figure out the problem. Even when the scene changes, the silhouetted image appears to be stationary about the origin. I would really appreciated any ideas as to what may be causing it, as I have tried everything I can think of with no success.

Thanks,
Steve

[This message has been edited by ssaunders (edited 02-12-2001).]

can you post some pics of the phenomena?

I dont have access to the code just now so I will post a picture and give details of where to find it sometime tomorrow afternoon (UK time).

Thanks,
Steve

Hello!!!
Have you disabled the “Depth Test”?
You have to disable the depth test when enable blending (glDepthMask(GL_FALSE)).

Otherwise you won´t see the objects back your transparent object.

First draw all your opaque objects, then disable the depht test, and draw all your translucent objects. I´m sure, it works!!!

Sorry my bad english, I´m Spanish.

Originally posted by Vero:
You have to disable the depth test when enable blending (glDepthMask(GL_FALSE)).

Depth test is disabled with:

glDisable(GL_DEPTH_TEST);

Using glDepthMask will enable or disable writes to the depth buffer.

Regards.

Eric

I have managed to fix the problem where the object appears to be obscured by a silhouette of itself, however I still cannot get the blending to work.

If I render the “transparent” object on its own it works, but when I render the opaque object first the “transparent” object is opaque as well!?!?

Thanks,
Steve

what kind of blend factors are you using with glBlendFunc??

The ones mentioned above:

GL_SRC_COLOR, GL_DST_COLOR);

Ive tried a few others in case it was them, but it made no difference.

Thanks,
Steve

hmmm you sure u you have set your Alpha-values correct.
The qpaquet object should have 1.0, and the translucent something like 0.25…

draw opaque object
glEnable[GL_BLEND); glBlendFunc(GL_SCR_ALPHA,GL_ONE_MINUS_SCR_ALPHA);
draw translucent object

now you shouuld see 75% of opaquet object and 25% of translucent object
hope that helps
Chris

I have set my alpha values for the material properties to 0.5 (50% transparency)…so I cant see that being the problem…as I said the transparency works if I only rendered the “transparent” surface.

Thanks,
Steve

Hmmm…why don’t you post you rcode here for us to take a look? That might help solve things a little faster for ya.

Here is an extract from my render_scene() function

glClearColor(0.0f,0.0f,0.0f,0.5f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

// ======== 1st Rendering pass with normal lighting ========
glEnable(GL_TEXTURE_2D);
glEnable(GL_DEPTH_TEST);
glLoadIdentity();
glPushMatrix();
glRotatef(rotationPositions[X],1.0f,0,0);
glRotatef(sceneroty,0,1.0f,0);

//Setup the lighting parameters
glLightfv(GL_LIGHT0, GL_AMBIENT, normal_light_amb);
glLightfv(GL_LIGHT0, GL_DIFFUSE, normal_light_dif);
glLightfv(GL_LIGHT0, GL_SPECULAR, normal_light_spec);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);

//translate to the position of the lander
glTranslatef(xtrans,ytrans,ztrans);

DrawSurface();

// ======== 2nd Rendering pass with normal lighting ========
glDisable(GL_TEXTURE_2D);
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE);
//Change the lighting parameters
glLightfv(GL_LIGHT0, GL_AMBIENT, backscatter_light_amb);
glLightfv(GL_LIGHT0, GL_DIFFUSE, backscatter_light_dif);
glLightfv(GL_LIGHT0, GL_SPECULAR, backscatter_light_spec);

DrawSurface();

Thanks,
Steve

Why do you clear with alpha = 0.5?

[This message has been edited by Relic (edited 02-15-2001).]

Originally posted by Relic:
Why do you clear with alpha = 0.5?

The material for both the opaque and transparent surfaces has the alpha value set to 0.5f. The problem seems to be with the glDepthMask function in that it doesn’t seem to make the depth buffer read only when doing the transparent object, hence it being opaque.

Does anyone think I this may be the problem ?

thanks,
Steve

The depth buffer should not affect the color buffer blending at all. If you say your transparent object comes out opaque that means no fragment rejection because of depth test fails has occured and color buffer blending isn’t done correctly.

Such problems should always be crosschecked with the MS GDI Generic OpenGL implementation if you have no other HW in reach.
Select a pixelformat with the PFD_GENERIC_FORMAT bit set in dwFlags and check the renderer string with glGetString(GL_VENDOR). It should say “Microsoft Corp.”.

If this implementation shows the same problem, you program is wrong, if not, you probably found a driver bug.