Results 1 to 2 of 2

Thread: Questions on Stencil and Dissolve

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2001
    Posts
    15

    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?


    Code :
     
    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

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Mar 2001
    Posts
    2,411

    Re: Questions on Stencil and Dissolve

    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.
    "If you can't afford to do something right,
    you'd better make sure you can afford to do it wrong!"

Similar Threads

  1. Dissolve between 2 images and loading ppm file
    By Yoghurt in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 11-09-2009, 12:59 PM
  2. Stencil buffer questions
    By Hylke Donker in forum OpenGL: Basic Coding
    Replies: 9
    Last Post: 01-17-2005, 10:53 AM
  3. questions about stencil buffer
    By romb in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 07-25-2002, 04:17 AM
  4. Stencil and depth buffer questions
    By imported_Anders in forum OpenGL: Advanced Coding
    Replies: 0
    Last Post: 01-23-2002, 04:16 AM
  5. How do you do this: a 'dissolve' effect.
    By Anonymous Coward in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 05-30-2001, 06:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean