Share this post

Link to post

Share on other sites

is allocating 4 texture objects, and placing them into the array "textures".

Right after you've set up your color texture for your FBO, you call:
gl.glGenTextures(5, textures, 0);

This is creating 5 new texture objects, and putting their handles in the same array (textures). This means that when you say tex1 = textures[3] later on, you're getting the handle to a texture with no image data backing it. It'll let you bind the texture, but drawing to it will cause an error. If you need 5 textures, just one call to glGenTextures(5,textures,0) at the beginning should work for you.

Second, I see you're attaching to the color and depth attachments, but not to the stencil. If memory serves, all three attachments are required for OpenGL to allow drawing to an FBO.

Do you need to read from your depth texture? If not, then you should probably generate a Renderbuffer, call glRenderbufferStorage() to set it up with a type such as GL_DEPTH24_STENCIL_8, and attach it to GL_DEPTH_STENCIL_ATTACHMENT instead of using your current depth texture. If you DO need to sample your depth buffer, then you'll still need to generate a renderbuffer, but of a type like GL_STENCIL_INDEX8, and attach it to just GL_STENCIL_ATTACHMENT.

EDIT: The following is probably irrelevant to JOGL, since it appears to only support up to OpenGL 2.0
One last thing: FBOs haven't been an extension for quite some time now. You might try removing the EXT from your calls/constants and see if that still works. (If you're using OpenGL 3 or 4 it should). I know that back when FBO's were still an extension they were a bit harder to work with.