Direct draw from one texture to another using FBOs

Hello,

Is there a way to attach one texture to one FBO, another texture to a different FBO and then read a part of first FBO and blit onto the other FBO and as a result make a permanent alteration of the texture the blit was done to through writing to the FBO that texture was attached to? I’m a beginner, just registered today, searched for the solution, but with no luck.

Is it possible to do with OpenGL like with SDL’s function:

int SDL_BlitSurface(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect);

Thanks in advance

Yes, there is such way.
Look for functions glBindFramebuffer, glBlitFramebuffer and glDrawBuffer/glReadBuffer.

Thanks. I’ve looked and its not working, or I misunderstood how to attach a texture to a FBO:

First I check to see if there is an extension in the extension string and there is. So what am I doing wrong?


if( Engine::AllOpenGLExtensionsAvailable )
        Engine::glGenFramebuffersEXT(1, &rFBO);

...
...

if( Engine::AllOpenGLExtensionsAvailable ) {

            Engine::glFramebufferTexture2DEXT( this->rFBO, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, this->rTexID, 0 );

            if( Engine::glCheckFramebufferStatusEXT(this->rFBO) != GL_FRAMEBUFFER_COMPLETE_EXT )
                rEngine->ReportError(ERR_CRITICAL, "Called Image::Attach FBO is not complete after attaching texture to it.");

...
...
...

void ZImage::Blit( ZImage &sourceImg, int x, int y )
{
    if( Engine::AllOpenGLExtensionsAvailable ) {

        Engine::glBindFramebufferEXT( GL_READ_FRAMEBUFFER_EXT, sourceImg.rFBO );
        Engine::glBindFramebufferEXT( GL_DRAW_FRAMEBUFFER_EXT, this->rFBO );

        rEngine->ReportError(ZERR_VERBOSE,"Blit: sourceImg.rFBO: %i, this->rFBO: %i", sourceImg.rFBO, this->rFBO);

        //glReadBuffer( GL_COLOR_ATTACHMENT1_EXT );
        //glDrawBuffer( GL_COLOR_ATTACHMENT0_EXT );

        Engine::glBlitFramebufferEXT(
                       0, 0, sourceImg.rWidth, sourceImg.rHeight,
                       x, y, x + sourceImg.rWidth, y + sourceImg.rHeight,
                       GL_COLOR_BUFFER_BIT,
                       GL_LINEAR
        );

        // unbind FBOs
        Engine::glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 );
        //Engine::glBindFramebufferEXT( GL_DRAW_FRAMEBUFFER_EXT, 0 );

    }
}


Honestly, I don’t have a clue on what I’m doing and the usage example that comes with glBindFramebuffer is so straightforward, so it should work. The problem with example present in the specs for that function is already have created FBOs and its not giving a complete example of how to attach already created texture, when it should be attached.

What I’m doing is creating a texture and FBO in the class constructor and then attaching that texture to that FBO:

Engine::glFramebufferTexture2DEXT( this->rFBO, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, this->rTexID, 0 );

But it seems that its not possible, because you can only attach texture to a GL_FRAMEBUFFER_EXT and not to the FBO created with:

Engine::glGenFramebuffersEXT(1, &rFBO);

In the above example all the variables like Engine::glGenFramebuffersEXT are obtained and valid OpenGL pointers. The app compiles but it crashes during run-time on the glBlitFramebufferEXT call with error 1280.

Can you help? I’m probably close, just found out about GLinterceptor and its giving me all bunch of errors:


GL ERROR - Function wglDescribePixelFormat generated error GL_INVALID_OPERATION
GL ERROR - Function wglDescribePixelFormat generated error GL_INVALID_OPERATION
GL ERROR - Function wglDescribePixelFormat generated error GL_INVALID_OPERATION
GL ERROR - Function wglDescribePixelFormat generated error GL_INVALID_OPERATION
GL ERROR - Function wglDescribePixelFormat generated error GL_INVALID_OPERATION
GL ERROR - Function wglDescribePixelFormat generated error GL_INVALID_OPERATION
GL ERROR - Function wglDescribePixelFormat generated error GL_INVALID_OPERATION
GL ERROR - Function wglDescribePixelFormat generated error GL_INVALID_OPERATION
GL ERROR - Function wglDescribePixelFormat generated error GL_INVALID_OPERATION
ExtensionFunction::AddFunction - Function glBindTexture does not match previous lookup (multiple OpenGL devices?)
ExtensionFunction::AddFunction - Function glGenTextures does not match previous lookup (multiple OpenGL devices?)
ExtensionFunction::AddFunction - Function glPopClientAttrib does not match previous lookup (multiple OpenGL devices?)
ExtensionFunction::AddFunction - Function glPushClientAttrib does not match previous lookup (multiple OpenGL devices?)
ExtensionFunction::AddFunction - Function glTexSubImage2D does not match previous lookup (multiple OpenGL devices?)
GL ERROR - Function glFramebufferTexture2DEXT generated error GL_INVALID_ENUM
GL ERROR - Function glCheckFramebufferStatusEXT generated error GL_INVALID_ENUM
GL ERROR - Function glFramebufferTexture2DEXT generated error GL_INVALID_ENUM
GL ERROR - Function glCheckFramebufferStatusEXT generated error GL_INVALID_ENUM
GL ERROR - Function glFramebufferTexture2DEXT generated error GL_INVALID_ENUM
GL ERROR - Function glCheckFramebufferStatusEXT generated error GL_INVALID_ENUM
GL ERROR - Function glFramebufferTexture2DEXT generated error GL_INVALID_ENUM
GL ERROR - Function glCheckFramebufferStatusEXT generated error GL_INVALID_ENUM
GL ERROR - Function glFramebufferTexture2DEXT generated error GL_INVALID_ENUM
GL ERROR - Function glCheckFramebufferStatusEXT generated error GL_INVALID_ENUM
GL ERROR - Function glFramebufferTexture2DEXT generated error GL_INVALID_ENUM
GL ERROR - Function glCheckFramebufferStatusEXT generated error GL_INVALID_ENUM
GL ERROR - Function glFramebufferTexture2DEXT generated error GL_INVALID_ENUM
GL ERROR - Function glCheckFramebufferStatusEXT generated error GL_INVALID_ENUM
GL ERROR - Function glFramebufferTexture2DEXT generated error GL_INVALID_ENUM
GL ERROR - Function glCheckFramebufferStatusEXT generated error GL_INVALID_ENUM
GL ERROR - Function glFramebufferTexture2DEXT generated error GL_INVALID_ENUM
GL ERROR - Function glCheckFramebufferStatusEXT generated error GL_INVALID_ENUM
GL ERROR - Function glFramebufferTexture2DEXT generated error GL_INVALID_ENUM
GL ERROR - Function glCheckFramebufferStatusEXT generated error GL_INVALID_ENUM
ImageManager::Destructor - OpenGL id 1 is still active. (Image Memory leak?)
ImageManager::Destructor - OpenGL id 2 is still active. (Image Memory leak?)
ImageManager::Destructor - OpenGL id 3 is still active. (Image Memory leak?)
ImageManager::Destructor - OpenGL id 4 is still active. (Image Memory leak?)
ImageManager::Destructor - OpenGL id 5 is still active. (Image Memory leak?)
ImageManager::Destructor - OpenGL id 6 is still active. (Image Memory leak?)
ImageManager::Destructor - OpenGL id 7 is still active. (Image Memory leak?)

I’m using it for 10 minutes, so need to see and read the documentation, it makes no sense to me.

Is there are better way to debug the problems with OpenGL?

Are you binding the FBO before calling glFramebufferTexture2DEXT( this->rFBO, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, this->rTexID, 0 )?

and there is something wrong with your code if wglDescribePixelFormat spits out GL_INVALID_OPERATION. You are probably making this mistake
http://www.opengl.org/wiki/Common_Mistakes#The_Object_Oriented_Language_Problem

Thanks

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.