Objective c OpenGL多纹理遮罩
我把@Stefan Monov的教程搁置了。一切都正常,但我需要用刷子让它正常工作。我需要这样做:Objective c OpenGL多纹理遮罩,objective-c,xcode,cocoa,opengl,alphablending,Objective C,Xcode,Cocoa,Opengl,Alphablending,我把@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 pi
// 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和代码的顺序,它现在根本不起作用。当我按照@Stefan Monov所描述的顺序离开时,它工作了,但当鼠标被拖动时,它会画一个点并拖动它。因为在绘制点之后,其他纹理也会被重新绘制。有没有,至少是类似的解决方案
为了更清楚,我将展示我希望我的应用程序如何工作 以下是原始代码:
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通道本身在最终图像中以任何方式都不可见
遮罩的唯一用途是修改其后面绘制的内容 你的应用程序试图做什么?你能发布一张你想要得到什么样结果的模型图片吗?解释一下我在看什么?那是一个静电面罩,还是某种油漆应用?它的油漆应用。在图像着色的地方,有一个笔刷笔划。对不起,我的英语不好。你有没有考虑过看一下模具缓冲区?我认为这比尝试混合更合适。我没有试过这个。只是掩蔽看起来更简单。我想我已经知道如何解决我的问题了。我只需要将鼠标坐标绘制到顶点数组,每次将值添加到顶点数组时,我都应该重新绘制遮罩纹理。因为现在一切正常,但我的画笔只画了一个彩色点,在mousedrag中,它只是用鼠标拖动那个彩色点。所以现在我将尝试这个解决方案。以后,如果我的解决方案不起作用,我会试试你的。谢谢:)