I have two surfaces.
One as the background (rendered first).
The other as my "canvas" (rendered last).
I found a very strange problem when I tried to use blending to achieve a transparent effect!
Even though I have rendered in the "recommended" rendering order, I still can't get the transparency effect...
I had to use some "tricks" to achieve the effect I wanted.
My compromise now is either to use glDepthFunc(GL_LEQUAL)
or to adjust the Z of the second surface a little(plus 0.001f
)...
glDepthFunc(GL_LEQUAL);
quad.Draw();//the background
glDepthFunc(GL_LESS);
or
std::vector<GLfloat> Vtx = {
1.0f, 1.0f, 0.0f, // top right
1.0f, -1.0f, 0.0f, // bottom right
-1.0f, -1.0f, 0.0f, // bottom left
-1.0f, 1.0f, 0.0f // top left
};
std::vector<GLfloat> Vtx2 = {
1.0f, 1.0f, 0.001f, // top right
1.0f, -1.0f, 0.001f, // bottom right
-1.0f, -1.0f, 0.001f, // bottom left
-1.0f, 1.0f, 0.001f // top left
};
I'd like to know why this is happening. Doesn't it follow the correct rendering order to correctly blend each object?
Is there a better way to achieve a transparent effect on those two surfaces?