我想使用在OpenGL alpha掩码,使得白色(1)=可见和黑色(0)=隐藏。

所以,我做的是我用glColorMask(False, False, False, True)写的东西在帧缓冲的alpha分量(我使用python,你看到的),然后绘制使用混合上面一些几何图形。

但它不工作: 我试图填充所述α0完全地缓冲,然后绘制一些几何形状应该因而是不可见的。但它总是显示了,α缓冲器被完全地忽略。

# Clear alpha buffer to 0, and clear color buffer.
# After this, the alpha buffer should probaby be filled with 0.
glClearColor(0, 0, 0, 0)
glClear(GL_COLOR_BUFFER_BIT)

# Disable blending.
glDisable(GL_BLEND)

# Disable color writing.
glColorMask(False, False, False, True)

# Set color to a white with alpha 0.
glColor4f(1, 1, 1, 0)

# Now draw a fullscreen quad.
# After this, the alpha buffer should really be filled with 0.
# Shouldn't it?
glBegin(GL_QUADS)
glVertex2f(0, 0)
glVertex2f(320, 0)
glVertex2f(320, 480)
glVertex2f(0, 480)
glEnd()

# Enable color writing.
glColorMask(True, True, True, True)

# Enable blending so that incoming fragments are multiplied
# by alpha values already in the buffer.
glEnable(GL_BLEND)
glBlendFunc(GL_DST_ALPHA, GL_ONE)

# Set color to a white with alpha 1.
glColor4f(1, 1, 1, 1)    

# Now draw a triangle.
# It should not be visible because alpha in framebuffer is 0
# and 0 * 1 = 0.
glBegin(GL_TRIANGLES)
glVertex2f(20, 50)
glVertex2f(300, 50)
glVertex2f(160, 210)
glEnd()

(是,投影矩阵是右,所以我的屏幕的范围从0/0到二百四十○分之三百二十〇。)

在三角应该是不可见的,我做了什么错?

有帮助吗?

解决方案

尝试询问用于阿尔法缓冲器当创建你GL背景下,如果你是不是已经。

其他提示

使用glAlphaFunc(GL_GREATER,0.5);

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top