PDA

View Full Version : FBO working for tex_rectangle but not tex_2d



codemonkey76
01-20-2009, 06:59 AM
geforce 6800 GT on ubuntu hardy, latest nvidia drivers.
So I'm messing with FBO, and just doing a simple RGBA render to texture. It works if I use GL_TEXTURE_RECTANGLE_ARB but I get a GL_FRAMEBUFFER_UNSUPPORTED_EXT error if I use GL_TEXTURE_2D instead. All necessary extensions seem to be present. I'm using GLEW for the binding points.
Any ideas on why it's only partially working? Thanks!

codemonkey76
01-20-2009, 07:00 AM
oh btw the texture size is 256x256. I don't think I'm doing anything weird, just trying to get it to work.

satan
01-20-2009, 07:34 AM
Just a guess, but do you create mipmaps?
I think some code could help.
My deferred renderer works with FBOs on a 6600GT on Ubuntu 8.10.

codemonkey76
01-20-2009, 09:21 AM
No, no mipmaps. Really simple stuff, I think. Here's a code sample. Change target to texture rectangle and it works on my machine, otherwise it doesn't. Crazy!?

GLuint fbo;
GLuint depthbuffer;
GLuint tex;
int texW = 512, texH = 512;
//GLenum target = GL_TEXTURE_RECTANGLE_ARB;
GLenum target = GL_TEXTURE_2D;

void CHECK_FRAMEBUFFER_STATUS()
{
switch( glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) )
{
case GL_FRAMEBUFFER_COMPLETE_EXT:
fprintf(stderr,"framebuffer complete!\n");
break;
case GL_FRAMEBUFFER_UNSUPPORTED_EXT:
fprintf(stderr,"framebuffer GL_FRAMEBUFFER_UNSUPPORTED_EXT\n");
break;
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT:
fprintf(stderr,"framebuffer INCOMPLETE_ATTACHMENT\n");
break;
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT:
fprintf(stderr,"framebuffer FRAMEBUFFER_MISSING_ATTACHMENT\n");
break;
case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
fprintf(stderr,"framebuffer FRAMEBUFFER_DIMENSIONS\n");
break;
case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT:
fprintf(stderr,"framebuffer INCOMPLETE_FORMATS\n");
break;
case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT:
fprintf(stderr,"framebuffer INCOMPLETE_DRAW_BUFFER\n");
break;
case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT:
fprintf(stderr,"framebuffer INCOMPLETE_READ_BUFFER\n");
break;
case GL_FRAMEBUFFER_BINDING_EXT:
fprintf(stderr,"framebuffer BINDING_EXT\n");
break;
}
}

static void init( void* )
{
glGenFramebuffersEXT(1, &fbo);
glGenTextures(1, &tex);

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
glBindTexture(target, tex);
glTexImage2D(target, 0, GL_RGBA, texW, texH, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);

glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, target, tex, 0);

CHECK_FRAMEBUFFER_STATUS();

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
}

static void render( void* )
{
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
glPushAttrib(GL_VIEWPORT_BIT);
glViewport(0,0,texW, texH);

glClearColor(0.0, 0.0, 1.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor4f( 1.0, 1.0, 1.0, 1.0);

glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho( 0, 1, 0, 1, -1, 1 );

glBegin(GL_LINES);
glColor4f( 1.0, 1.0, 1.0, 1.0);
glVertex2f( 0.0, 0.0 );
glVertex2f( 1.0, 1.0 );
glEnd();

glPopAttrib();
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
///////////////

glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glViewport(0,0,winSize[0], winSize[1]);

glEnable( target );

glBindTexture(target, tex);
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho( 0, 1, 0, 1, -1, 1 );
glBegin( GL_QUADS );
glTexCoord2i( 0, 0 );
glVertex2i( 0, 0 );
glTexCoord2i( 512, 0 );
glVertex2i( 1, 0 );
glTexCoord2i( 512, 512 );
glVertex2i( 1, 1 );
glTexCoord2i( 0, 512 );
glVertex2i( 0, 1 );
glEnd();

glDisable( target );
}

codemonkey76
01-20-2009, 10:18 AM
it's strange, because i'm getting the GL_FRAMEBUFFER_UNSUPPORTED_EXT error, indicating there must be some bad combination of size, internal format, etc. Confusing, then, that the texture rectangle works...

codemonkey76
01-20-2009, 10:27 AM
ok, i fixed it by adding
glTexParameteri( target, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
glTexParameteri( target, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
glTexParameteri( target, GL_TEXTURE_WRAP_S, GL_CLAMP );
glTexParameteri( target, GL_TEXTURE_WRAP_T, GL_CLAMP );
before the glTexImage2D call.
It must be that the default values for these for GL_TEXTURE_2D are not compatible with FBO's, and furthermore the default values for GL_TEXTURE_RECTANGLE must be different since mipmaps are handled differently.

And now the solution is recorded for all time in the tubes...
;-)

ZbuffeR
01-20-2009, 11:18 AM
... and it is an incomplete solution :)
the default texture filtering is linear mipmap.
mipmap is disabled with texture rectangle.
so you wanted to draw mipmaped texture but without any mipmaps defined.

you should do this to your texture :
glGenerateMipmapEXT(GL_TEXTURE_2D);

some more details here :
http://www.songho.ca/opengl/gl_fbo.html

codemonkey76
01-20-2009, 04:00 PM
Good to know about the generate mipmap function, but for now I don't care about mipmaps and am just trying to get it to work. If you don't want mipmaps, you have to use NEAREST or LINEAR or else the texture is invalid. If I add the mipmap call with any of the MIPMAP filters, then it also works.
Thanks!