I'm writing a 2d game engine using libgdx where multiple layers of sprites have to be rendered using SpriteBatch with an OrthgraphicCamera. My layers are sorted with a z component : higher z layers should be rendered on top of layers with a lower z.
Currently, I have to render layers sorted by their z component to achieve that. Is there a way, using opengl Z-buffer, to have them rendered out of order, and still show up correctly ?
CodePudding user response:
Fixed by switching to DecalBatch
instead of SpriteBatch. Here are the GL commands I use before drawing with the DecalBatch to enable depth-testing :
Gdx.gl.apply {
glClearColor(0f, 0f, 0f, 0f);
glEnable(GL20.GL_DEPTH_TEST)
glClear(GL20.GL_COLOR_BUFFER_BIT or GL20.GL_DEPTH_BUFFER_BIT)
glClearDepthf(1f)
glDepthFunc(GL20.GL_LESS)
}