Results 1 to 7 of 7

Thread: glcolormask with only alpha enabled does not work?

  1. #1

    glcolormask with only alpha enabled does not work?

    Who can provide me with extra info on the glcolormask?
    For my vector graphics project i need 2 different fills one with color and one on the alpha channel.
    So i thought i could do:
    Code:

    //draw fill
    glColorMask(TRUE,TRUE, TRUE, FALSE); //but not yet alpha
    fStyle.DrawFill(fBoundBoxRadius);

    //draw fill alpha
    glColorMask(FALSE,FALSE,FALSE, TRUE);
    fStyle.DrawAlphaFill(fBoundBoxRadius);



    But the alpha channel does not get set. Only if i enable the colors in the second part i get the alpha channel working. But then the collors are all wrong... as i blend white over other colors.

    Thanks in advance for your ideas on how to solve this.


    [EDIT]
    Meanwhile i have been playing around with using different blend modes together with the colormask settings
    on drawing the fill i use glBlendFunc(GL_DST_COLOR, GL_ZERO) and on the alpha glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) and the result looks ok'ish.

    More on blend modes: http://jerome.jouvie.free.fr/OpenGl/.../Tutorial9.php
    [/EDIT]
    http://3das.noeska.com - create adventure games without programming

  2. #2

    Re: glcolormask with only alpha enabled does not work?

    Render without any of the R,G,B is not really doing anything at all. Alpha value is merely a multiplicator for them which isn't written to any buffer as itself. I think you will need to use
    glColorMask(TRUE,TRUE,TRUE,TRUE);
    for desired effect but we may need more detailed info about the wanted looks to help

  3. #3

    Re: glcolormask with only alpha enabled does not work?

    what i want is to fill a shape with a raidial gradient and for the tranparenci i want to use a different radial fill.

    E.g. Like this: (color fill, alpha fill, blended end result)


    This is my current code that works ok'ish ( but i suspect it to bleech )
    Code:
      //draw alpha fill
      glBlendFunc(GL_DST_COLOR, GL_ZERO);
      glColorMask(TRUE,TRUE,TRUE, TRUE);
      fStyle.DrawAlphaFill(fBoundBoxRadius,fboundboxminpoint, fboundboxmaxpoint);
    
      //draw fill
      glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_DST_ALPHA);
      glColorMask(TRUE,TRUE, TRUE, FALSE); //but not alpha
      fStyle.DrawFill(fBoundBoxRadius,fboundboxminpoint,fboundboxmaxpoint);
    http://3das.noeska.com - create adventure games without programming

  4. #4

    Re: glcolormask with only alpha enabled does not work?

    Another problem came along.
    As i use the the stencil buffer now i get problems when 2 shapes overlap. E.g. no transparency anymore. An shape that is not drawn with the stencil buffer gives proper transparency.
    http://3das.noeska.com - create adventure games without programming

  5. #5

    Re: glcolormask with only alpha enabled does not work?

    Another testcase: (seems to work ok'ish)
    It draws 2 quads (red and blue) on a green quad. The 2 quads have gradient transparency.
    [code=pascal]
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_BLEND);

    glcolor4f(0,1,0,1);
    glbegin(GL_QUADS);
    glVertex3f(0, 480, 0.0); // Top Left
    glVertex3f(640, 480, 0.0); // Top Right

    glVertex3f(640, 0, 0.0); // Bottom Right
    glVertex3f(0, 0, 0.0); // Bottom Left
    glend;

    //FIRST QUAD

    //turning off writing to the color buffer and depth buffer so we only
    //write to stencil buffer
    glColorMask(FALSE, FALSE, FALSE, FALSE);
    //enable stencil buffer
    glEnable(GL_STENCIL_TEST);
    //write a one to the stencil buffer everywhere we are about to draw
    glStencilFunc(GL_ALWAYS, 2, $FFFFFFFF);
    //this is to always pass a one to the stencil buffer where we draw
    glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
    //draw shape

    glbegin(GL_QUADS);
    glVertex3f(0, 260, 0.0); // Top Left
    glVertex3f(280, 260, 0.0); // Top Right
    glVertex3f(280, 0, 0.0); // Bottom Right
    glVertex3f(0, 0, 0.0); // Bottom Left
    glend;

    //until stencil test is diabled, only write to areas where the
    //stencil buffer has a one. This fills the shape
    glStencilFunc(GL_EQUAL, 2, $FFFFFFFF);
    // don't modify the contents of the stencil buffer
    glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);


    //draw alpha fill
    glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glColorMask(FALSE,FALSE,FALSE, TRUE);

    glbegin(GL_QUADS);
    glcolor4f(1,1,1,1); //SOLID
    glVertex3f(0, 260, 0.0); // Top Left
    glVertex3f(280, 260, 0.0); // Top Right
    glcolor4f(1,1,1,0.0); //TRANSPARENT
    glVertex3f(280, 0, 0.0); // Bottom Right
    glVertex3f(0, 0, 0.0); // Bottom Left
    glend;

    //draw fill
    glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA);
    glColorMask(TRUE,TRUE, TRUE, FALSE); //but not alpha

    glbegin(GL_QUADS);
    glcolor4f(1,0,0,1); //RED
    glVertex3f(0, 260, 0.0); // Top Left
    glVertex3f(280, 260, 0.0); // Top Right
    glVertex3f(280, 0, 0.0); // Bottom Right
    glVertex3f(0, 0, 0.0); // Bottom Left
    glend;

    //'default' rendering again
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glColorMask(TRUE,TRUE, TRUE, TRUE);
    glDisable(GL_STENCIL_TEST);

    //SECOND QUAD

    //turning off writing to the color buffer and depth buffer so we only
    //write to stencil buffer
    glColorMask(FALSE, FALSE, FALSE, FALSE);
    //enable stencil buffer
    glEnable(GL_STENCIL_TEST);
    //write a one to the stencil buffer everywhere we are about to draw
    glStencilFunc(GL_ALWAYS, 4, $FFFFFFFF);
    //this is to always pass a one to the stencil buffer where we draw
    glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
    //draw shape

    glbegin(GL_QUADS);
    glVertex3f(100, 360, 0.0); // Top Left
    glVertex3f(380, 360, 0.0); // Top Right
    glVertex3f(380, 100, 0.0); // Bottom Right
    glVertex3f(100, 100, 0.0); // Bottom Left
    glend;

    //until stencil test is diabled, only write to areas where the
    //stencil buffer has a one. This fills the shape
    glStencilFunc(GL_EQUAL, 4, $FFFFFFFF);
    // don't modify the contents of the stencil buffer
    glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);


    //draw alpha fill
    glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glColorMask(FALSE,FALSE,FALSE, TRUE);

    glbegin(GL_QUADS);
    glcolor4f(1,1,1,1); //SOLID
    glVertex3f(100, 360, 0.0); // Top Left
    glVertex3f(380, 360, 0.0); // Top Right
    glcolor4f(1,1,1,0.0); //TRANSPARENT
    glVertex3f(380, 0, 0.0); // Bottom Right
    glVertex3f(100, 100, 0.0); // Bottom Left
    glend;

    //draw fill
    glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA);
    glColorMask(TRUE,TRUE, TRUE, FALSE); //but not alpha

    glbegin(GL_QUADS);
    glcolor4f(0,0,1,1); //BLUE
    glVertex3f(100, 360, 0.0); // Top Left
    glVertex3f(380, 360, 0.0); // Top Right
    glVertex3f(380, 100, 0.0); // Bottom Right
    glVertex3f(100, 100, 0.0); // Bottom Left
    glend;

    //'default' rendering again
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glColorMask(TRUE,TRUE, TRUE, TRUE);
    glDisable(GL_STENCIL_TEST);
    [/code]
    http://3das.noeska.com - create adventure games without programming

  6. #6

    Re: glcolormask with only alpha enabled does not work?

    Maybe multitexturing is thing you are after? It allows you to use another texture for transparency only.

  7. #7

    Re: glcolormask with only alpha enabled does not work?

    I try to avoid going the texture way. I am afraid to end up with large textures.
    http://3das.noeska.com - create adventure games without programming

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •