Following SigTerm's suggestion, I render all my opaque polygons first, and then I disable the depth buffer (glDepthMask(GL_FALSE)
) before I render my translucent polygons.
As soon as I disable the depth buffer though, it stops drawing anything to the screen. I can only see a glimpse of the world as I move the camera around (only little pieces show up for a second, and then disappear when I stop moving).
If I leave the depth buffer enabled the whole time, everything renders fine, it's just not as nice as I'd like (translucent objects obscure other translucent objects).
How do I get it to render properly?
My main render loop looks like this:
protected void RenderTerrain()
{
GL.Enable(EnableCap.DepthTest);
GL.Enable(EnableCap.CullFace);
_bfShader.Use();
_bfProjUniform.Mat4(_viewMat * _bfProjMat);
_bfTex.Bind();
GL.DepthMask(true);
GL.Disable(EnableCap.Blend);
_blendUniform.Set1(false);
_bfVao.Bind();
GL.DrawElementsInstancedBaseVertex(BeginMode.TriangleStrip, SharedData.FaceIndices.Length, DrawElementsType.UnsignedInt, IntPtr.Zero, _bfInstBuf.Length, 0);
GL.DepthMask(false);
GL.Enable(EnableCap.Blend);
_blendUniform.Set1(true);
_transVao.Bind();
GL.DrawElementsInstancedBaseVertex(BeginMode.TriangleStrip, SharedData.FaceIndices.Length, DrawElementsType.UnsignedInt, IntPtr.Zero, _bfTransBuf.Length, 0);
}
The other half of the render loop:
protected override void OnRenderFrame(FrameEventArgs e)
{
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
lock(_renderQueue)
{
while(_renderQueue.Count > 0)
{
_renderQueue.Dequeue().Invoke();
}
}
RenderTerrain();
RenderHUD();
SwapBuffers();
}
Can you reenable the glDepthMask before calling glClear(), or at the end of your render loop?
Preventing writes to the depth buffer will prevent it from being correctly cleared.
http://www.opengl.org/wiki/FAQ#Masking
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With