Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: why not transparent?

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2008
    Posts
    7

    why not transparent?

    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()

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Apr 2004
    Posts
    999

    Re: why not transparent?

    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);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •