2012-07-03 80 views
0

我休闲@Stefan Monov教程this question。一切正常,但我需要使它与我的画笔合作。我需要这样做:OpenGL多纹理蒙版

// Next, we want a blendfunc that doesn't change the color of any pixels, 
// but rather replaces the framebuffer alpha values with values based 
// on the whiteness of the mask. In other words, if a pixel is white in the mask, 
// then the corresponding framebuffer pixel's alpha will be set to 1. 
glBlendFuncSeparate(GL_ZERO, GL_ONE, GL_SRC_COLOR, GL_ZERO); 
// Now "draw" the mask (again, this doesn't produce a visible result, it just 
// changes the alpha values in the framebuffer) 
drawQuad(maskTexture); 

将不是一个静态纹理,但动态形状。我的意思是,我试图实施刷女巫是做@Stefan Monov写的这样的事情。所以我需要这个地方可以在其他 - (void)函数中实现,以便在坐标改变时(用户绘制时)调用它。我尝试了多种方法来改变代码的顺序,但它不能正确工作。现在我的密码是:

glEnable(GL_BLEND); 
glBlendFuncSeparate(GL_ZERO, GL_ONE, GL_SRC_COLOR, GL_ZERO); 
glPointSize(100); 
glBegin(GL_POINTS); 
glColorMask(1.0,1.0,1.0, 1.0); 
glVertex2f(loc.x, loc.y); 
glEnd(); 
glDisable(GL_BLEND); 

当拖动鼠标时会调用它。 “loc”是拖动鼠标的坐标。由于blendFunc和代码的顺序,它现在根本不工作。当我像@Stefan Monov所描述的那样离开序列时,它会起作用,但当鼠标被拖动时,它会绘制一个点并拖动它。在绘制点之后,其他纹理也正在重绘。任何,至少类似的解决方案呢?


为了更清楚地说明我将展示我的APP如何工作。

这里是原代码:

glEnable(GL_BLEND); 
glBlendFunc(GL_ONE, GL_ZERO); 
drawQuad(backgroundTexture); 

glBlendFuncSeparate(GL_ZERO, GL_ONE, GL_SRC_COLOR, GL_ZERO); 
drawQuad(maskTexture); 

glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA); 
drawQuad(foregroundTexture); 

现在,它的工作是这样的:

  1. 绘制背景
  2. 绘制面具
  3. 绘制前景

我需要它像这样工作:

  1. 绘制bacground
  2. 绘制前景
  3. 绘制掩模

但是,如果我改变附图的顺序它停止工作。忽略掩码。

预期的结果照片: enter image description here

+0

你的应用程序试图做什么?你可以发布你试图获得什么样的结果的模型图像吗? – Tim

+0

是的。当然。发布编辑。 – hockeyman

+0

解释我在看什么?这是一个静态掩码,或为某种绘画应用程序? – Tim

回答

0

您试图绘制面具最后是没有意义的真。

绘制蒙版仅修改Alpha通道中的内容,并且Alpha通道本身在最终图像中不可见。

该面具的唯一用途是修改后面绘制的内容。