[英]OpenGL multi texture masking
在这个问题中,我不喜欢@Stefan Monov教程。 一切正常,但是我需要使用笔刷使其正常工作。 我需要这样做:
// 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)函数中实现,以便在坐标更改时(用户绘制时)可以调用它。 我尝试了多种方法来更改代码的顺序,但是那时它无法正常工作。 现在我的bursh代码是:
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和代码的顺序,Afcourse现在根本不起作用。 当我按照@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);
现在其工作方式如下:
我需要它像这样工作:
但是,如果我更改图纸顺序,它将停止工作。 忽略面具。
预期结果照片:
您最后一次绘制面具的尝试确实没有任何意义。
绘制蒙版仅会修改alpha通道中的内容,并且alpha通道本身在最终图像中不可见。
遮罩的唯一用途是修改其后绘制的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.