DGL
https://delphigl.com/forum/

glcolormask with only alpha channel enabled does not work?
https://delphigl.com/forum/viewtopic.php?f=19&t=8638
Seite 1 von 1

Autor:  noeska [ Di Aug 25, 2009 11:50 ]
Betreff des Beitrags:  glcolormask with only alpha channel 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:
  1.  
  2.     //draw fill
  3.     glColorMask(TRUE,TRUE, TRUE, FALSE); //but not yet alpha
  4.     fStyle.DrawFill(fBoundBoxRadius);
  5.  
  6.     //draw fill alpha
  7.     glColorMask(FALSE,FALSE,FALSE, TRUE);
  8.     fStyle.DrawAlphaFill(fBoundBoxRadius);
  9.  


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/Tut ... orial9.php
[/EDIT]

Autor:  noeska [ Mi Aug 26, 2009 09:49 ]
Betreff des Beitrags: 

The current status (with quads for simplicity):
Renders 2 quads (red and blue) on a green quad. The 2 quads have a linear gradient on the alpha.
Seems ok'ish.

Code:
  1.   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  2.   glEnable(GL_BLEND);
  3.  
  4.   glcolor4f(0,1,0,1);
  5.   glbegin(GL_QUADS);
  6.       glVertex3f(0, 480, 0.0);      // Top Left
  7.       glVertex3f(640, 480, 0.0);        // Top Right
  8.  
  9.       glVertex3f(640, 0, 0.0);      // Bottom Right
  10.       glVertex3f(0, 0, 0.0);        // Bottom Left
  11.   glend;
  12.  
  13.   //FIRST QUAD
  14.  
  15.   //turning off writing to the color buffer and depth buffer so we only
  16.   //write to stencil buffer
  17.   glColorMask(FALSE, FALSE, FALSE, FALSE);
  18.   //enable stencil buffer
  19.   glEnable(GL_STENCIL_TEST);
  20.   //write a one to the stencil buffer everywhere we are about to draw
  21.   glStencilFunc(GL_ALWAYS, 2, $FFFFFFFF);
  22.   //this is to always pass a one to the stencil buffer where we draw
  23.   glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
  24.   //draw shape
  25.  
  26.   glbegin(GL_QUADS);
  27.       glVertex3f(0, 260, 0.0);      // Top Left
  28.       glVertex3f(280, 260, 0.0);        // Top Right
  29.       glVertex3f(280, 0, 0.0);      // Bottom Right
  30.       glVertex3f(0, 0, 0.0);        // Bottom Left
  31.   glend;
  32.  
  33.   //until stencil test is diabled, only write to areas where the
  34.   //stencil buffer has a one. This fills the shape
  35.   glStencilFunc(GL_EQUAL, 2, $FFFFFFFF);
  36.   // don't modify the contents of the stencil buffer
  37.   glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
  38.  
  39.  
  40.   //draw alpha fill
  41.   glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  42.   glColorMask(FALSE,FALSE,FALSE, TRUE);
  43.  
  44.   glbegin(GL_QUADS);
  45.     glcolor4f(1,1,1,1); //SOLID
  46.       glVertex3f(0, 260, 0.0);      // Top Left
  47.       glVertex3f(280, 260, 0.0);        // Top Right
  48.     glcolor4f(1,1,1,0.0); //TRANSPARENT
  49.       glVertex3f(280, 0, 0.0);      // Bottom Right
  50.       glVertex3f(0, 0, 0.0);        // Bottom Left
  51.   glend;
  52.  
  53.   //draw fill
  54.   glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA);
  55.   glColorMask(TRUE,TRUE, TRUE, FALSE); //but not alpha
  56.  
  57.   glbegin(GL_QUADS);
  58.     glcolor4f(1,0,0,1); //RED
  59.       glVertex3f(0, 260, 0.0);      // Top Left
  60.       glVertex3f(280, 260, 0.0);        // Top Right
  61.       glVertex3f(280, 0, 0.0);      // Bottom Right
  62.       glVertex3f(0, 0, 0.0);        // Bottom Left
  63.   glend;
  64.  
  65.   //'default' rendering again
  66.   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  67.   glColorMask(TRUE,TRUE, TRUE, TRUE);
  68.   glDisable(GL_STENCIL_TEST);
  69.  
  70.   //SECOND QUAD
  71.  
  72.     //turning off writing to the color buffer and depth buffer so we only
  73.   //write to stencil buffer
  74.   glColorMask(FALSE, FALSE, FALSE, FALSE);
  75.   //enable stencil buffer
  76.   glEnable(GL_STENCIL_TEST);
  77.   //write a one to the stencil buffer everywhere we are about to draw
  78.   glStencilFunc(GL_ALWAYS, 4, $FFFFFFFF);
  79.   //this is to always pass a one to the stencil buffer where we draw
  80.   glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
  81.   //draw shape
  82.  
  83.   glbegin(GL_QUADS);
  84.       glVertex3f(100, 360, 0.0);        // Top Left
  85.       glVertex3f(380, 360, 0.0);        // Top Right
  86.       glVertex3f(380, 100, 0.0);        // Bottom Right
  87.       glVertex3f(100, 100, 0.0);        // Bottom Left
  88.   glend;
  89.  
  90.   //until stencil test is diabled, only write to areas where the
  91.   //stencil buffer has a one. This fills the shape
  92.   glStencilFunc(GL_EQUAL, 4, $FFFFFFFF);
  93.   // don't modify the contents of the stencil buffer
  94.   glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
  95.  
  96.  
  97.   //draw alpha fill
  98.   glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  99.   glColorMask(FALSE,FALSE,FALSE, TRUE);
  100.  
  101.   glbegin(GL_QUADS);
  102.     glcolor4f(1,1,1,1); //SOLID
  103.       glVertex3f(100, 360, 0.0);        // Top Left
  104.       glVertex3f(380, 360, 0.0);        // Top Right
  105.     glcolor4f(1,1,1,0.0); //TRANSPARENT
  106.       glVertex3f(380, 0, 0.0);      // Bottom Right
  107.       glVertex3f(100, 100, 0.0);        // Bottom Left
  108.   glend;
  109.  
  110.   //draw fill
  111.   glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA);
  112.   glColorMask(TRUE,TRUE, TRUE, FALSE); //but not alpha
  113.  
  114.   glbegin(GL_QUADS);
  115.     glcolor4f(0,0,1,1); //BLUE
  116.       glVertex3f(100, 360, 0.0);        // Top Left
  117.       glVertex3f(380, 360, 0.0);        // Top Right
  118.       glVertex3f(380, 100, 0.0);        // Bottom Right
  119.       glVertex3f(100, 100, 0.0);        // Bottom Left
  120.   glend;
  121.  
  122.   //'default' rendering again
  123.   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  124.   glColorMask(TRUE,TRUE, TRUE, TRUE);
  125.   glDisable(GL_STENCIL_TEST);


Are there beter ways? Also i still get confused be the blendfunc.

Seite 1 von 1 Alle Zeiten sind UTC + 1 Stunde
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/