View Full Version : Messed up blending problem

12-30-2004, 06:43 AM
Dear All,

I really need some help with blending and transparency, as I think I'm getting all confused with source/destination/materials etc.

I am trying to create a solid opaque object that is covered by a transparent object.

I first render the opaque object before rendering the transpareny object using the following, standard code:

matdiff[0] = 1.0f;
matdiff[1] = 1.0f;
matdiff[2] = 1.0f;
matdiff[3] = 1.0f;
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, matdiff);

<Use vertex array to draw opaque object>

matdiff[3] = 0.6f;
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, matdiff);

glBlendFunc(GL_SRC_ALPHA, GL_ONE);

<use vertex array to draw transparent object>


This code all works ok, but I am a bit unhappy about the way the blending looks. The overlapping objects seem to glow (the colors I think are 'multiplied' together), so I started playing around with the Blending Function, which I simply changed to:


This gives me what I want! The glow is gone, and the transparency looks great... Except for one little problem...

The triangles aren't quite right - there is something wrong with the rendering of polygons, perhaps with depth testing I suspect (because it looks great from some angles, but then when I move it, there is a clear line afterwhich the rendering goes all funny).

Can anyone please help? Many thanks in advance!

Best wishes,


12-30-2004, 09:44 AM
heres a windows app i wrote a few years ago, that explains the math behind blending (it uses fltk so u might need that installed, not sure)