abe*_*thy 5 python opengl alpha blending
我想在OpenGL中使用alpha蒙版,以便白色(1)=可见,黑色(0)=隐藏.
所以我要做的是在framebuffer的alpha组件中使用glColorMask(False, False, False, True)(我正在使用python,你看),然后使用混合在它上面绘制一些几何体.
但它不起作用:我尝试用0填充alpha缓冲区,然后绘制一些因此不可见的几何体.但它始终显示,alpha缓冲区被完全忽略.
# 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()
Run Code Online (Sandbox Code Playgroud)
(是的,投影矩阵是正确的,所以我的屏幕范围从0/0到320/240.)
三角形不应该是可见的,我做错了什么?
| 归档时间: |
|
| 查看次数: |
4215 次 |
| 最近记录: |