I want to use an alpha mask in OpenGL so that white (1) = visible and black (0) = hidden.
So what I do, I write something in the alpha component of the framebuffer using glColorMask(False, False, False, True)(I use python, you see) and then draw some geometry over it using blending.
But it does not work: I tried to completely fill the alpha buffer 0, and then drew some geometry, which, therefore, would not be visible. But it always appears, the alpha buffer is completely ignored.
glClearColor(0, 0, 0, 0)
glClear(GL_COLOR_BUFFER_BIT)
glDisable(GL_BLEND)
glColorMask(False, False, False, True)
glColor4f(1, 1, 1, 0)
glBegin(GL_QUADS)
glVertex2f(0, 0)
glVertex2f(320, 0)
glVertex2f(320, 480)
glVertex2f(0, 480)
glEnd()
glColorMask(True, True, True, True)
glEnable(GL_BLEND)
glBlendFunc(GL_DST_ALPHA, GL_ONE)
glColor4f(1, 1, 1, 1)
glBegin(GL_TRIANGLES)
glVertex2f(20, 50)
glVertex2f(300, 50)
glVertex2f(160, 210)
glEnd()
(Yes, the projection matrices are right, so my screen ranges from 0/0 to 320/240.)
The triangle should not be visible, what did I do wrong?