Sign in to follow this  
alb

invalid framebuffer operation with FBO

Recommended Posts

I have a problem with this piece of code:

[source lang="java"]gl.glGenTextures(4, textures, 0);
gl.glBindTexture(GL.GL_TEXTURE_2D, textures[3]);
gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGB, floorWidth, floorHeight,0, GL.GL_RGB, GL.GL_FLOAT, null);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP);



gl.glGenTextures(5, textures, 0);
gl.glBindTexture(GL.GL_TEXTURE_2D, textures[4]);
gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_DEPTH_COMPONENT16, floorWidth, floorHeight,0, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, null);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);


int tex1=textures[3];
int tex2=textures[4];




//GENERATE FRAMEBUFFER
gl.glGenFramebuffersEXT(1, frameBufferID, 0);


gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, frameBufferID[0]);



gl.glFramebufferTexture2DEXT(GL.GL_FRAMEBUFFER_EXT, GL.GL_COLOR_ATTACHMENT0_EXT,GL.GL_TEXTURE_2D, tex1, 0);
gl.glFramebufferTexture2DEXT(GL.GL_FRAMEBUFFER_EXT, GL.GL_DEPTH_ATTACHMENT_EXT, GL.GL_TEXTURE_2D, tex2, 0);




if(gl.glCheckFramebufferStatusEXT(GL.GL_FRAMEBUFFER_EXT) == GL.GL_FRAMEBUFFER_COMPLETE_EXT)
{
System.out.println("[Viewer] GL_FRAMEBUFFER_COMPLETE!!");
}
else
System.out.println("..error");


gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, 0);
[/source]
At the end of this initialization code, I have an FBO (frame buffer object) with no errors;
it prints "[Viewer] GL_FRAMEBUFFER_COMPLETE!!"

But when I try to render something:

[source lang="java"] GL gl = drawable.getGL();

gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, frameBufferID[0]);
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glPushAttrib(GL.GL_VIEWPORT_BIT);
gl.glViewport(0, 0, floorWidth, floorHeight);

gl.glBegin(GL.GL_QUADS);

gl.glTexCoord2f(0.0f, 0.0f);
gl.glVertex3d(-1, -1, 0);
gl.glTexCoord2f(0.0f, 1.0f);
gl.glVertex3d(-1, 1, 0);
gl.glTexCoord2f(1.0f, 1.0f);
gl.glVertex3d(1, 1, 0);
gl.glTexCoord2f(1.0f, 0.0f);
gl.glVertex3d(1, -1, 0);

gl.glEnd();


gl.glPopAttrib();
gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, 0);

gl.glPopAttrib();
gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, 0);


int errorCode = gl.glGetError();
if(errorCode!=0){
String errorStr = glu.gluErrorString( errorCode );
System.out.println("...error: "+ errorStr );
System.out.println("....errorCode: "+ errorCode );
}

[/source]

It return the following error:

....error: invalid framebuffer operation
....errorCode: 1286

Do you know why?
Thanks.
Alberto

Share this post


Link to post
Share on other sites
I believe it more looks syntax call error than frame buffer problem. Your code:
[code]

gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, frameBufferID[0]);
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glPushAttrib(GL.GL_VIEWPORT_BIT); // <--- You saved viewport bits
gl.glViewport(0, 0, floorWidth, floorHeight);

gl.glBegin(GL.GL_QUADS);

gl.glTexCoord2f(0.0f, 0.0f);
gl.glVertex3d(-1, -1, 0);
gl.glTexCoord2f(0.0f, 1.0f);
gl.glVertex3d(-1, 1, 0);
gl.glTexCoord2f(1.0f, 1.0f);
gl.glVertex3d(1, 1, 0);
gl.glTexCoord2f(1.0f, 0.0f);
gl.glVertex3d(1, -1, 0);

gl.glEnd();


gl.glPopAttrib(); // <-- You restored previous attribute values (viewport bits)
gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, 0);

gl.glPopAttrib(); // <-- What it does restore???
gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, 0);
[/code]

Best wishes, FXACE. Edited by FXACE

Share this post


Link to post
Share on other sites
[quote name='FXACE' timestamp='1341443376' post='4955793']
I believe it more looks syntax call error than frame buffer problem. Your code:
[code]

gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, frameBufferID[0]);
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glPushAttrib(GL.GL_VIEWPORT_BIT); // <--- You saved viewport bits
gl.glViewport(0, 0, floorWidth, floorHeight);

gl.glBegin(GL.GL_QUADS);

gl.glTexCoord2f(0.0f, 0.0f);
gl.glVertex3d(-1, -1, 0);
gl.glTexCoord2f(0.0f, 1.0f);
gl.glVertex3d(-1, 1, 0);
gl.glTexCoord2f(1.0f, 1.0f);
gl.glVertex3d(1, 1, 0);
gl.glTexCoord2f(1.0f, 0.0f);
gl.glVertex3d(1, -1, 0);

gl.glEnd();


gl.glPopAttrib(); // <-- You restored previous attribute values (viewport bits)
gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, 0);

gl.glPopAttrib(); // <-- What it does restore???
gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, 0);
[/code]

Best wishes, FXACE.
[/quote]


No the last two rows are a copy&paste error:

[CODE]
gl.glPopAttrib(); // <-- You restored previous attribute values (viewport bits)
gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, 0);
[/CODE]

Share this post


Link to post
Share on other sites
A couple of things..
[CODE]
gl.glGenTextures(4, textures, 0);
[/CODE]

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:
[CODE]
gl.glGenTextures(5, textures, 0);
[/CODE]

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.

[b]EDIT: The following is probably irrelevant to JOGL, since it appears to only support up to OpenGL 2.0 [/b]
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.

Good luck, I hope this helps! Edited by Alukien

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this