Transparency / Blending Problem

Hi,

I have a problem with my semi-transparent planes. If I draw the red one first, then the blue one, the blue one is not drawn where they overlap.

My DrawFunc
GLvoid MyClass: :DrawMyStuff()
glEnable(GL_DEPTH_TEST);
glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE,mat_ambient);
if(drawPoly)
ObjList->Draw(GL_TRIANGLE_STRIP);

  if(drawConnected)
  	ObjList->Draw(GL_LINE_STRIP);
  glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE,mat_ones);
  if(drawPoints)
  {
  	glPointSize(2.0f);
  	ObjList->Draw(GL_POINTS);
  }

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);

  if(VPlane1)
  	DrawVPlane(VPlane1Pos);

  if(VPlane2)
  	DrawVPlane(VPlane2Pos);

  if(HPlane1)
  	DrawHPlane(HPlane1Pos);

  if(HPlane2)
  	DrawHPlane(HPlane2Pos);

  glDisable(GL_BLEND);

}

GLvoid MyClass: :DrawHPlane(int pos)
{
GLfloat mat = { 1.0, 0.0, 0.0, 0.5 };
glBegin(GL_QUADS);
glColor3d(0.75f, 0.0f, 0.25);
glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE,mat);
glVertex3d(-400.0, pos, -300.0);
glVertex3d(-400.0, pos, 300.0);
glVertex3d(400.0, pos, 300.0);
glVertex3d(400.0, pos, -300.0);
glEnd();
}

GLvoid MyClass: :DrawVPlane(int pos)
{
GLfloat mat = { 0.0, 0.0, 1.0, 0.75 };
glBegin(GL_QUADS);
glColor3d(0.25f, 0.0f, 0.75);
glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE,mat);
glVertex3d( pos,-10.0, -300.0);
glVertex3d( pos,-10.0, 300.0);
glVertex3d( pos, 1200.0, 300.0);
glVertex3d( pos, 1200.0, -300.0);
glEnd();
}

Could you guys tell me what’s wrong about this??

Thanks,

Martin

[This message has been edited by mphanke (edited 04-22-2002).]

You need to disable Z-writes when drawing semi-transparent polys, so that one poly doesn’t prevent another one from drawing if it’s behind or equal in depth.

Use glDepthMask(GL_FALSE); before drawing transparent stuff.

Restore it again afterwards… with glDepthMask(GL_TRUE);

Nutty

Thanks Nutty!

Martin

Draw your transparent objects from back to front (farthest first) with depth writing disabled.

/niko

Gee, Nutty, you’re fast

/Niko

Thanks to you Niko, too!
Do you know of any good Tutorial on materials and stuff?? I’m fighting as sh** with this stuff!

Martin

[This message has been edited by mphanke (edited 04-22-2002).]

Originally posted by mphanke:
Do you know of any good Tutorial on materials and stuff??

Nehe comes to mind. Still, I think the tips Nutty and I gave to you are the essentials you need to know to make your blending thingies work.

/Niko