PDA

View Full Version : GL_DST_ALPHA blending



yossi
02-16-2006, 12:21 AM
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

Bob
02-16-2006, 01:04 AM
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.

02-16-2006, 01:11 AM
Thanks Bob,
I will check the alpha bits.