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