FBO's - I cant make render to depth buffer work
Posted by phil1234 on Oct 17, 2016; 2:44pm
URL: https://forum.jogamp.org/FBO-s-I-cant-make-render-to-depth-buffer-work-tp4037322.html
Hi,
I am getting insane trying to make this work
the point is to get the depth buffer values (with FBOs) for later post processing in a shader
once I add a depth texture, the framebuffer gets corrupted, and I really dont understand what's going on
some say to use render buffer, some say I should use textures instead
plz healp
public void createFrameBuffer(GL2ES2 gl,int width,int height,SceneGraph frameBufferSceneGraph,boolean depthBuffer)
{
this.frameBufferSceneGraph=frameBufferSceneGraph;
frameBufferObject = genFBO(gl);
gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, frameBufferObject);
Texture frameBufferTexture=material.getDiffuseTexture();
frameBufferTexture.bind(gl);
gl.glFramebufferTexture2D(GL.GL_FRAMEBUFFER, GL.GL_COLOR_ATTACHMENT0, GL.GL_TEXTURE_2D, frameBufferTexture.getTextureObject(), 0);
if(depthBuffer)
{
depthBufferTexture=Tools.createEmptyTexture(gl,frameBufferTexture.getWidth(),frameBufferTexture.getHeight(),Color.yellow);
depthBufferTexture.bind(gl);
gl.glFramebufferTexture2D(GL.GL_FRAMEBUFFER, GL.GL_DEPTH_ATTACHMENT, GL.GL_TEXTURE_2D, depthBufferTexture.getTextureObject(), 0);
}
gl.glDrawBuffers(1,new int[]{GL.GL_COLOR_ATTACHMENT0},0);
if (gl.glCheckFramebufferStatus(GL.GL_FRAMEBUFFER) != GL.GL_FRAMEBUFFER_COMPLETE)
System.err.println("Error! FrameBuffer is not complete");
gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, 0);
//System.out.println("frameBufferObject: "+frameBufferObject+" renderBuffer:"+renderBuffer);
}
thanks