PDA

View Full Version : problem using fbo, please HELP



fazekaim
07-04-2005, 08:39 PM
Hello!

I'm tryin to use FBO.
I created an FBO instance with an GL_TEXTURE_2D texture attached to GL_COLOR_ATTACHMENT0_EXT.
When I use like this:


gl.glBindFramebufferEXT( GL.GL_FRAMEBUFFER_EXT, FBO[0] );
//gl.glPushMatrix();
//gl.glScalef( 1.0f, -1.0f, 1.0f );
render();
//gl.glPopMatrix();

gl.glBindFramebufferEXT( GL.GL_FRAMEBUFFER_EXT, 0 );
render();
After calling the first time the render method the fbo texture is a black.
What do I make wrong?
(sorry, for the bad english)

Thanks...

fbo creation method:


public static void createNewFrameBuffer(int width, int height, int[] FBO, int[] FBORenderBuffer, int[] FBOTexture ){

gl.glGenFramebuffersEXT( 1, FBO );
gl.glBindFramebufferEXT( GL.GL_FRAMEBUFFER_EXT, FBO[0] );

gl.glGenTextures( 1, FBOTexture );
//gl.glBindFramebufferEXT( GL.GL_FRAMEBUFFER_EXT, FBOTexture[0] );
gl.glBindTexture( GL.GL_TEXTURE_2D, FBOTexture[0] );
gl.glTexImage2D( GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, width, height, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, BufferUtils.bufferOffset(0) );
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.glFramebufferTexture2DEXT( GL.GL_FRAMEBUFFER_EXT, GL.GL_COLOR_ATTACHMENT0_EXT, GL.GL_TEXTURE_2D, FBOTexture[0], 0 );

gl.glGenRenderbuffersEXT( 1, FBORenderBuffer );
gl.glBindRenderbufferEXT( GL.GL_RENDERBUFFER_EXT, FBORenderBuffer[0] );
gl.glRenderbufferStorageEXT( GL.GL_RENDERBUFFER_EXT, GL.GL_DEPTH_COMPONENT24, width, height );
gl.glFramebufferRenderbufferEXT( GL.GL_FRAMEBUFFER_EXT, GL.GL_DEPTH_ATTACHMENT_EXT, GL.GL_RENDERBUFFER_EXT, FBORenderBuffer[0] );

if( !checkFrameBufferStatus( width, height ) ){
JOptionPane.showMessageDialog(null, "FBO jajjajj", "Unavailable extension", JOptionPane.ERROR_MESSAGE);
System.exit( -1 );
}

gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, 0);
}
private static boolean checkFrameBufferStatus(int width, int height) {
int status = gl.glCheckFramebufferStatusEXT( GL.GL_FRAMEBUFFER_EXT );
switch(status) {
case GL.GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENTS_EXT:
log( "Framebuffer status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT" +status);
return false;
case GL.GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EX T:
log( "Framebuffer status = GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT" +status);
return false;
case GL.GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_ EXT:
log( "Framebuffer status = GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT" +status);
return false;
case GL.GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
log( "Framebuffer status = GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT" +status);
return false;
case GL.GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT:
log( "Framebuffer status = GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT"+status);
return false;
case GL.GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT:
log( "Framebuffer status = GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT"+status);
return false;
case GL.GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT:
log( "Framebuffer status = GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT" );
return false;
case GL.GL_FRAMEBUFFER_COMPLETE_EXT:
log( "Successfully created the frame buffer object < " +
width + ", " + height + ">" );
return true;
case GL.GL_FRAMEBUFFER_UNSUPPORTED_EXT:
log("Failed to create the frame buffer object, please verify your format");
return false;
default:
log("????? FBO ????????");
return false;
}
}

Henry Jones
07-04-2005, 11:41 PM
hi

i had a problem when using GL_TEXTURE_2D,
so i had to use GL_TEXTURE_RECTANGLE_NV instead

this example worked for me ( under linux with a nvidia-card)
http://openvidia.sourceforge.net/fbo.shtml

i hope this will help

k.arts
07-10-2005, 01:52 AM
Hi!
I had the same problem and solved it this way:
I just generated fbos in the init step (glGen...)
I did NOT attached the fbo to an texture there.
(You can do so, but it won't change a thing in this solution)
When drawing to the FBO I attached the texture :
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, FBO);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, Tex,0);

That worked for me. And using GL_TEXTURE_2D is okay.
Hope that helped

fazekaim
07-10-2005, 11:07 AM
Thanks.

I'm using a texture with the size of the screen (1024x768) and not a power of 2.
And it is working now with GL_TEXTURE_2D.

I can't set the coordinate for reflectiong my objects.
my code:


public void display(GLDrawable glDrawable) {
{
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT );
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
glu.gluLookAt( eye.x, eye.y, eye.z, focus.x, focus.y, focus.z, up.x, up.y, up.z );

gl.glBindFramebufferEXT( GL.GL_FRAMEBUFFER_EXT, FBO[0] );
gl.glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
gl.glClear( GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glPushMatrix();
gl.glScalef( 1.0f, -1.0f, 1.0f );
renderScene();
gl.glPopMatrix();

gl.glBindFramebufferEXT( GL.GL_FRAMEBUFFER_EXT, 0 );
gl.glClearColor(0.0f, 1.0f, 0.0f, 0.0f);
gl.glClear( GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT );
gl.glPushMatrix();
renderscene();
renderWater();
gl.glPopMatrix();
}

private void EnableWaterTextureMatrix(){
gl.glMatrixMode( GL.GL_TEXTURE );

gl.glScalef(0.5f, 0.5f, 1.0f);
gl.glTranslatef(1.0f, 1.0f, 0.0f);
float[] modelMatrix = new float[16];gl.glGetFloatv(GL.GL_MODELVIEW_MATRIX, modelMatrix);
float[] projectionlMatrix = new float[16];gl.glGetFloatv(GL.GL_PROJECTION_MATRIX, projectionlMatrix);
gl.glMultMatrixf( modelMatrix );
gl.glMultMatrixf( projectionlMatrix );

gl.glMatrixMode( GL.GL_MODELVIEW );
}

private void DisableWaterTextureMatrix() {
gl.glMatrixMode( GL.GL_TEXTURE );
gl.glLoadIdentity();
gl.glMatrixMode( GL.GL_MODELVIEW );
}

public void renderWater() {

EnableWaterTextureMatrix();

gl.glEnable( GL.GL_DEPTH_TEST);
gl.glEnable(GL.GL_MULTISAMPLE_ARB);

gl.glActiveTextureARB( GL.GL_TEXTURE0_ARB + 0);
gl.glBindTexture( GL.GL_TEXTURE_2D, FBOTexture[0]);
gl.glClientActiveTextureARB( GL.GL_TEXTURE0_ARB + 0);
gl.glEnable( GL.GL_TEXTURE_2D);

gl.glBegin( GL.GL_QUADS);
gl.glMultiTexCoord2f( 0, 1, 1 );
gl.glVertex3f( vertexes[0][0], waterLevel, vertexes[0][1] );

gl.glMultiTexCoord2f( 0, 1 , 0 );
gl.glVertex3f( vertexes[1][0], waterLevel, vertexes[1][1] );

gl.glMultiTexCoord2f( 0, 0, 0 );
gl.glVertex3f( vertexes[2][0], waterLevel, vertexes[2][1] );

gl.glMultiTexCoord2f( 0, 0, 1 );
gl.glVertex3f( vertexes[3][0], waterLevel, vertexes[3][1] );
gl.glEnd();

gl.glActiveTextureARB( GL.GL_TEXTURE0_ARB + 0);
gl.glDisable( GL.GL_TEXTURE_2D);
gl.glClientActiveTextureARB( GL.GL_TEXTURE0_ARB + 0);

gl.glDisable( GL.GL_BLEND );

DisableWaterTextureMatrix();

}
It renders well the water plane with the fbo texture, but I don't know how to compute reflection texture coordinates.