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 3 of 3

Thread: GL_DST_ALPHA blending

  1. #1
    Junior Member Regular Contributor
    Join Date
    Aug 2000
    Location
    Haifa, ISRAEL
    Posts
    101

    GL_DST_ALPHA blending

    I am breaking my head finding why this simple code doesn't work:

    glDisable(GL_TEXTURE_2D);
    glDisable(GL_ALPHA_TEST);

    glClear(GL_COLOR_BUFFER_BIT);

    // Write alpha 0.5 in the color buffer
    // color blue
    glColor4f(0.0, 0.0, 1.0, 0.5);
    glBegin(GL_QUADS);
    glVertex2d(0, 0);
    glVertex2d(0, WIN_HEIGHT);
    glVertex2d(WIN_WIDTH, WIN_HEIGHT);
    glVertex2d(WIN_WIDTH, 0);
    glEnd();

    // Use that already 0.5 alpha in the color buffer
    // for blending
    glEnable(GL_BLEND);
    glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA);

    // color red blended with blue blended with the
    // red color in the frame buffer
    glColor3f(1.0, 0.0, 0.0);
    glBegin(GL_QUADS);
    glVertex2d(0, 0);
    glVertex2d(0, WIN_HEIGHT/2);
    glVertex2d(WIN_WIDTH/2, WIN_HEIGHT/2);
    glVertex2d(WIN_WIDTH/2, 0);
    glEnd();

    glDisable(GL_BLEND);

    When I render I see solid red rectangle NOT blended in the previous blue one. Using more blend modes give me hint that the alpha in the frame buffer is 1.0 and not 0.5 as I expect.

    WHY? What am I missing here?
    Thanks

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    3,115

    Re: GL_DST_ALPHA blending

    Do you actually have an alpha channel in the frame buffer? Unless you explicitely ask for an alpha channel when setting the pixel format, you may not get an alpha channel.

    Check glGetInteger with GL_ALPHA_BITS to see how many bits are in the alpha channel. If zero, you don't have an alpha channel.

  3. #3
    Guest

    Re: GL_DST_ALPHA blending

    Thanks Bob,
    I will check the alpha bits.

Posting Permissions

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