Questions on Stencil and Dissolve

Hi ,
I need to dissolve ‘Polygon A’ into the ‘Polygons B’. What does glDepthMask(False) do and how is it different than glDisable(GL_DEPTH_TEST) ?

Below is what I am doing. I am working on Delphi, hence the source is in pascal. If I use gldepthMask(False) then it blends ok, otherwise it does not. Why ?

Additionally could someone point me to white paper on how stencil buffer work?

CONST
zval = 0.0;

Procedure DrawB;
Begin
glColor4f(1,1,0,0.7);
glBegin(GL_POLYGON);
glVertex3d(-2.0,-0.8,zval);
glVertex3d(-2.0,-2.0,zval);
glVertex3d(2.0,-2.0,zval);
glVertex3d(2.0,-0.8,zval);
glEnd();

glColor4f(1,0,1,0.6);
glBegin(GL_POLYGON);
glVertex3d(-2.0,0.0,zval);
glVertex3d(2.0,0.0,zval);
glVertex3d(2.0,1.0,zval);
glVertex3d(-2.0,1.0,zval);
glEnd();
End;

Procedure DrawA;
Const
outside : Array [0…6] of TCoordArray = ( ( 0.0, 2.0, zval ),
( -1.0, -2.0, zval ),
( -0.8, -2.0, zval ),
( -0.4, -0.4, zval ),
( 0.4, -0.4, zval ),
( 0.8, -2.0, zval ),
( 1.0, -2.0, zval ));
Begin
glColor4f(1,0,0,0.5);
glBegin(GL_POLYGON);
glVertex3dv(@outside[0]);
glVertex3dv(@outside[1]);
glVertex3dv(@outside[2]);
glVertex3dv(@outside[3]);
glVertex3dv(@outside[4]);
glVertex3dv(@outside[5]);
glVertex3dv(@outside[6]);
glEnd;
End;

procedure PaintGL;
begin
glViewport(0,0,Width,Height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity;
glortho(-3.0, 3.0, -3.0, 3.0, -6.0, 6.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity;
glEnable(GL_BLEND);
glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_ALPHA);
glClearColor(1.0,1.0,1.0,0.0);
glClear(GL_COLOR_BUFFER_BIT Or GL_DEPTH_BUFFER_BIT or GL_STENCIL_BUFFER_BIT);
glClearStencil(0);
glEnable(GL_DEPTH_TEST);

glEnable(GL_STENCIL_TEST);
gldepthmask(false);

glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
glStencilFunc(GL_EQUAL, 0,1);

Drawb;

glStencilFunc(GL_GEQUAL, 1,1);
glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE );

Drawa;

glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
glStencilFunc( GL_EQUAL, 0, 1 );

Drawa;

glDisable(GL_STENCIL_TEST);
glDisable(GL_BLEND);
glDisable(GL_DEPTH_TEST);

SwapBuffers(SDC);

end;

DPS

The Enable/Disable controls BOTH the depth test, and the depth write.

The depth function determines whether a fragment passes the depth test or not.

The depth mask determines whether the depth buffer is written to after a fragment has passed the depth test or not.

The reason to have a separate enable/disable (as opposed to setting the depth mask to FALSE and the function to ALWAYS) is that the invariance rules are affected by the enable/disable, but not by the “straight through” function setting.

Also, if you think of a driver as writing custom vertex programs on the fly when you enable/disable states, you can see that calling Disable(DEPTH_TEST) would re-write a new vertex program with no depth information in it, whereas changing the function or mask could (conceivably) use the same program, but just change constants used by that program. I’m not sure current vertex programmable hardware could actually implement it that way, but previous software implementations certainly could.