Reputation: 319
I have drawn two polygons with 50% transparency, but it works only in one side (look images).
Goood blending:
But from another point of view:
Blue tubes are the axis with 0% transparency.
Here's the code of initialization:
qglClearColor(QColor::fromCmykF(0.39, 0.39, 0.0, 0.0));
glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
And drawing:
static const GLfloat P1[3] = { 0.0, -1.0, +2.0 };
static const GLfloat P2[3] = { +1.73205081, -1.0, -1.0 };
static const GLfloat P3[3] = { -1.73205081, -1.0, -1.0 };
static const GLfloat P4[3] = { 0.0, +2.0, 0.0 };
static const GLfloat * const coords[4][3] = {
{ P1, P2, P3 }, { P1, P3, P4 }, { P1, P4, P2 }, { P2, P4, P3 }
};
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0, 0.0, -10.0);
glScalef(scaling, scaling, scaling);
glRotatef(rotationX, 1.0, 0.0, 0.0);
glRotatef(rotationY, 0.0, 1.0, 0.0);
glRotatef(rotationZ, 0.0, 0.0, 1.0);
for (int i = 0; i < 2; ++i) {
glLoadName(i);
glBegin(GL_POLYGON);
QColor color = faceColors[i];
color.setAlpha(50);
qglColor(color);
for (int j = 0; j < 3; ++j) {
glVertex3f(coords[i][j][0], coords[i][j][1],
coords[i][j][2]);
}
glEnd();
}
My point is to draw and explore scene like this one
(source: wblut.com)
Upvotes: 0
Views: 149
Reputation: 2874
The problem lies in rendering with both blending and depth-testing. When a part of the geometry is found to be behind another part of geometry in the scene by the depth-test, it is discarded instead of blended.
To solve this, render in two steps
glDisable(GL_BLEND);
glDepthMask(GL_TRUE);
// Render solid geometry here
glEnable(GL_BLEND);
glDepthMask(GL_FALSE);
// Render transparent geometry here
In the first step solid geometry is drawn as usual without blending. Transparent geometry is drawn in the second pass without changing the depth buffer. Depth-testing is still enabled to avoid blending over solid geometry in front of the transparent parts.
Upvotes: 1