View Single Post
Old 01-27-07, 11:29 AM   #4
squeen
Registered User
 
Join Date: Dec 2006
Location: Greenbelt, MD
Posts: 33
Default Re: Frame buffer object with RGBA+z doesn't work for me..

Here are two methods that work for me ( 8800GTX, Quadro FX 4500 & Quadro FX 5500). The first creates and off-screen render target which can be read back using glReadPixels(), the other is a render to texture.
Code:
   GLuint   fb, color_rb, depth_rb, rgba_tex, depth_tex, i;
   
   glGenFramebuffersEXT(1, &fb);
   glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, fb );
switch (rtarget->class) {
      case CnFramebufferObjectRenderTargetClass:
         /* depth render buffer */
         glGenRenderbuffersEXT(1, &depth_rb);
         glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, depth_rb );
         glRenderbufferStorageEXT( GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, rtarget->width, rtarget->height );
         glFramebufferRenderbufferEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depth_rb );         
         rtarget->fbo.depth_attach = depth_rb;
         /* color render buffer */
         glGenRenderbuffersEXT(1, &color_rb);
         glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, color_rb );
         glRenderbufferStorageEXT( GL_RENDERBUFFER_EXT, GL_RGBA8, rtarget->width, rtarget->height );
         glFramebufferRenderbufferEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, color_rb );
         rtarget->fbo.color_attach[0] = color_rb;
         break;
      case CnRGBATextureRenderTargetClass:
                  
         /* RGBA texture  */
         glGenTextures(1, &rgba_tex);
         glBindTexture(GL_TEXTURE_2D, rgba_tex);
         glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
         glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
         glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, rtarget->width, rtarget->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL );
         glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, rgba_tex, 0 );         
         rtarget->fbo.color_attach[0] = rgba_tex;
         cnCheckGLerrors("cnNewFramebufferObject: fbo rgba texture");
         
         /* depth render buffer */
         glGenRenderbuffersEXT(1, &depth_rb);
         glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, depth_rb );
         glRenderbufferStorageEXT( GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, rtarget->width, rtarget->height );
         glFramebufferRenderbufferEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depth_rb );         
         rtarget->fbo.depth_attach = depth_rb;
         cnCheckGLerrors("cnNewFramebufferObject: fbo depth render buffer");
         
         break;
}
squeen is offline   Reply With Quote