I want to render my scene to a texture and apply a blur shader to this texture .The problem is that when I draw back my texture the front faces of the cubes are invisible
without supersampling
with supersampling
*Ignore the opaque thing around the cube in both photos.I double render the cube once with less alpha and more scale ,I disabled this but I have the same problem.
For some reason I am using the y as z and z as y,so the front face of the cube has less y than the back face(instead of z) ,I am guessing something is wrong with the z-buffer.
The render to texture code:
public class RenderOnTexture {
private float m_fboScaler = 1f;
private boolean m_fboEnabled = true;
private FrameBuffer m_fbo = null;
private TextureRegion m_fboRegion = null;
public RenderOnTexture(float scale) {
int width = (int) (Gdx.graphics.getWidth()*scale);
int height = (int) (Gdx.graphics.getHeight()*scale);
m_fbo = new FrameBuffer(Format.RGB565, (int)(width * m_fboScaler), (int)(height * m_fboScaler), false);
m_fboRegion = new TextureRegion(m_fbo.getColorBufferTexture());
m_fboRegion.flip(false,false);
}
public void begin(){
if(m_fboEnabled)
{
m_fbo.begin();
Gdx.gl.glClearColor(0, 0,0,0);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
}
}
public TextureRegion end(){
if(m_fbo != null)
{
m_fbo.end();
return m_fboRegion;
}
return null;
}
}
The Boolean argument in the FrameBuffer enables a depth buffer attachment. And the depth buffer must be cleared along with the color buffer.