I need to create a completely transparent surface passing through the origin of the axes and always parallel to the screen.
I'm trying to use this code (in c++
) but the result is something like 50% blend (not completely):
glPushMatrix();
glLoadIdentity();
glBlendFunc(1, 1);
glBegin(GL_QUADS);
glVertex3f(-100, -100, -0.003814);
glVertex3f(100, -100, -0.003814);
glVertex3f(100, 100, -0.003814);
glVertex3f(-100, 100, -0.003814);
glEnd();
glPopMatrix();
Additional informations: I need this transparent surface to get a point on it with the function gluUnProject(winX, winY, winZ, model, proj, view, &ox, &oy, &oz);
The blend function you are using is known as additive blending:
Final Color = (SourceColor * 1.0) + (DestinationColor * 1.0).
This is anything but fully transparent, unless the framebuffer is already fully white at the location you are blending (DestinationColor == (1.0, 1.0, 1.0)). And even then this behavior only works if you are using a fixed-point render target, because values are clamped to [0.0,1.0] after blending by default.
Instead, consider
glBlendFunc (GL_ZERO, GL_ONE)
:Final Color = (SourceColor * 0.0) + (DestinationColor * 1.0).
[...]
Final Color = Original Color
That said, you will probably get better performance if you simply use a color mask to disable color writes as genpfault suggested. Using a blending function to discard the color of your surface is needlessly complicated.