PDA

View Full Version : why not transparent?



usfish
03-30-2008, 06:23 PM
I think the alpha channel controls the transparency of the colors, and I think the following code should generate a almost transparent sphere, through which we can see a triangle. But can anyone tell me why it doesn't work?

Thanks, it is in PyOpenGL

glTranslatef( 0.15, 0.15, 0 )
glColor4f(0.5, 0.9, 0.3, 0.0025 ) # almost transparent
glutSolidSphere( 0.5, 40, 40 )

glPushMatrix()

glTranslatef( 0.15, 0.15, -0.1)
glColor4f(1, 0, 0, 0.25)

glBegin(GL_TRIANGLES)
glVertex3f( 0.0, 1.0, 0.0)
glVertex3f(-1.0,-1.0, 0.0)
glVertex3f( 1.0,-1.0, 0.0)
glEnd()

glPopMatrix()
glFlush()

-NiCo-
03-30-2008, 11:59 PM
You'll need to enable blending and choose the right blend function. Something like:

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);