Hi all!
Currently I am using FBOs for shadow mapping. I ported the code from my C++/OpenGL program to Java/JOGL and unfortunately the code does not work properly.
Here is my code to generate the FBO and depth texture:
gl.glGenFramebuffersEXT(1, fboHandleBuffer, 0);
m_DepthRendererObj = fboHandleBuffer[0];
gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, m_DepthRendererObj);
final int[] shadow=new int[1];
gl.glGenTextures(1, shadow, 0);
m_ShadowDepthTexture=shadow[0];
gl.glBindTexture(GL.GL_TEXTURE_2D,m_ShadowDepthTexture);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST );
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST );
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_COMPARE_FUNC, GL.GL_LEQUAL);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_COMPARE_MODE, GL.GL_COMPARE_R_TO_TEXTURE);
gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_DEPTH_COMPONENT16, depth_size, depth_size, 0, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, null);
gl.glDrawBuffer(GL.GL_NONE);
gl.glReadBuffer(GL.GL_NONE);
gl.glFramebufferTexture2DEXT(GL.GL_FRAMEBUFFER_EXT, GL.GL_DEPTH_ATTACHMENT_EXT, GL.GL_TEXTURE_2D, m_ShadowDepthTexture, 0);
First of all it is not possible to generate a texture with mag and min filtering set to linear and attach it to a FBO. I tried it with several color textures and it always throws an exception in the glFramebufferTexture2DEXT-line. If I set the min and mag filtering to nearest it works. Linear filtering should work in general and it works fine with C++ and OpenGL.
So if I use the depth texture with nearest filtering it can be created, but it never writes anything to it. I initialised it the same way as I do in my other programs - but it does not work. I read back the pixels from the texture and they are all set to 1.
If I disable the FBO and depth render to the normal render buffer I can read the pixels back and they hold different values - the way it should be.
To make a long story short:
- Is there any known bug with JOGL concerning linear filtered textures attached to FBOs? I haven’t found any info on the web.
- Do I have to call the functions in a different order to make it work?
- Has anyone tried rendering to depth textures through an FBO with JOGL?
3a) and if - what do I have to change to make it work?
Thanks!
Dee