Hi.
I’m just starting with the FBOs thing, and right from the start I’m getting some unexpected problems.
Basically what I want to do is the classic render-to-texture but I can’t figure out how to set up the FBO correctly.
Here’s my code (I’m doing this in the init() method of my listener):
// create the FBOs, texture objects and renderbuffers
System.out.println("Setting up framebuffer objects...");
fbos = new int[layers.length];
gl.glGenFramebuffersEXT(layers.length, fbos, 0);
textures = new int[layers.length];
gl.glGenTextures(layers.length, textures, 0);
// now for each layer
int i,status;
for (i=0; i<layers.length; i++)
{
// bind the corresponding FBO
gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, fbos[i]);
// initialize texture image
gl.glBindTexture(GL.GL_TEXTURE_2D, textures[i]);
gl.glTexImage2D(GL.GL_TEXTURE_2D, 0,
GL.GL_RGBA, 512, 512, 0,
GL.GL_RGBA, GL.GL_INT, null);
// attach texture to framebuffer color buffer #0
gl.glFramebufferTexture2DEXT(GL.GL_FRAMEBUFFER_EXT,
GL.GL_COLOR_ATTACHMENT0_EXT,
GL.GL_TEXTURE_2D, textures[i], 0);
// check framebuffer completeness
status = gl.glCheckFramebufferStatusEXT(GL.GL_FRAMEBUFFER_EXT);
if (status != GL.GL_FRAMEBUFFER_COMPLETE_EXT)
{
String str = "Framebuffer initialization error! ("+status+")\n";
throw new RuntimeException(str);
}
}
Really simple. Just generate the identifiers, bind the FBO, generate a texture image and bind it to the FBO’s color buffer.
So… what’s wrong? The ‘status’ variable returns with a value of 36054, which seems to be GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENTS_EXT. What’s missing in this code? Any help would be really appreciated.
Btw, if I do this afterwards:
if ((err = gl.glGetError()) != GL.GL_NO_ERROR) {
System.err.println ("ERROR [OpenGL] " + new GLU().gluErrorString(err));
}
I get a ‘null’ string from gluErrorString(). Is this expected behavior?
Thanks for any help.