5

OpenGLでアルファマスクを使用して、white(1)=表示およびblack(0)=非表示にします。

だから私がやっていることは、フレームバッファのアルファコンポーネントにglColorMask(False, False, False, True)(私は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から320/240です。)

三角形が表示されるべきではありません、私は何を間違えましたか?

4

2 に答える 2

3

GLコンテキストを作成するときに、まだ作成していない場合は、アルファバッファを要求してみてください。

于 2010-01-27T20:44:58.830 に答える
0

glAlphaFunc(GL_GREATER、0.5);を使用します。

于 2010-01-26T02:14:28.503 に答える