fast permanent texture to texture fast draw


I’m new to OpenGL. I’m trying to write a game that first checks if the appropriate extensions are present and if they are use fast texture to texture drawing to generate a game map at the beginning of each level.

The following code is giving me 1280 error:

void Image::Blit( Image &sourceImg, int x, int y )
    if( Engine::AllOpenGLExtensionsAvailable ) {
        Engine::glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, this->rTexID, 0 );
        Engine::glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_2D, sourceImg.rTexID, 0 );

        glReadBuffer( GL_COLOR_ATTACHMENT1_EXT );
        glDrawBuffer( GL_COLOR_ATTACHMENT0_EXT );

                       0, 0, sourceImg.rWidth, sourceImg.rHeight,
                       x, y, x + sourceImg.rWidth, y + sourceImg.rHeight,

        // unbind FBO
        Engine::glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 );
    } else {
        // TODO - normal SDL surface to surface blit

This is the code I’ve come up with after reading the documentation, but its not working. The glBlitFramebufferEXT specs are having a sample, but its not working either. If I create the two FBOs I don’t know how to attach textures to created FBOs so that the blit could be performed.

The extensions are present and the pointers to all the necessary functions are stored as static properties of Engine class. Everything is working properly except call to glBlitFramebufferEXT which produces a crash. And calls to glFramebufferTexture2DEXT are producing 1280 error.

Can you please point me into right reading material, I’m trying to make this work for … um … a week or so … lol


I don’t see the glbindframebufferEXT call at the start of the function?

Depending upon your drivers, FramebufferBlit may or may or be supported by your h/w. Have you made an assumption that blit is available because you have framebufferEXT, or have you actually checked the extenstion explicitly?

Of course, everything is like I said in my previous post

I wanted to pinpoint just the problematic piece of the code, but here is the part that checks the extensions. The extensions are present in the string, yes:

void Engine::checkOpenGL()
    // set the OpenGL version string
    Engine::OpenGL_version.append( (const char *)glGetString( GL_VERSION ) );
    std::string allglextensions( (const char *)glGetString( GL_EXTENSIONS ) );

    if( isExtensionSupported( "GL_EXT_framebuffer_blit", allglextensions ) && isExtensionSupported( "GL_EXT_framebuffer_object", allglextensions ) ) Engine::AllOpenGLExtensionsAvailable = true;
    else Engine::AllOpenGLExtensionsAvailable = false;
    // if there are extensions, set all the static OpenGL extension function pointers
    if( Engine::AllOpenGLExtensionsAvailable == true ) {

        Engine::glIsFramebufferEXT = (PFNGLISFRAMEBUFFEREXTPROC) wglGetProcAddress( "glIsFramebufferEXT" );
        Engine::glDeleteFramebuffersEXT = (PFNGLDELETEFRAMEBUFFERSEXTPROC) wglGetProcAddress( "glDeleteFramebuffersEXT" );
        Engine::glGenFramebuffersEXT = (PFNGLGENFRAMEBUFFERSEXTPROC) wglGetProcAddress( "glGenFramebuffersEXT" );
        //Engine::glFramebufferRenderbufferEXT = (PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC) wglGetProcAddress( "glFramebufferRenderbufferEXT" );
        Engine::glFramebufferTexture2DEXT = (PFNGLFRAMEBUFFERTEXTURE2DEXTPROC) wglGetProcAddress( "glFramebufferTexture2DEXT" );
        Engine::glCheckFramebufferStatusEXT = (PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC) wglGetProcAddress( "glCheckFramebufferStatusEXT" );
        Engine::glBindFramebufferEXT = (PFNGLBINDFRAMEBUFFEREXTPROC) wglGetProcAddress( "glBindFramebufferEXT" );
//        Engine::glBlitFramebufferEXT = (PFNGLBLITFRAMEBUFFEREXTPROC) wglGetProcAddress( "glBlitFramebufferEXT" );



My OpenGL version is 3.1.2, I just updated glext.h to your latest 3.2 and it gets the appropriate function pointers. Everything is working, its just that I’m not really sure how to use that blit function to read from one texture and write to another, to make permanent alteration of that other texture. The game level map is made of smaller ones. This works smoothly using SDL surface blit but its slow and there are some runtime alterations that needs to be done permanently on the level map, depending on the action during game.

Originally, I was creating FBO for each class Image instance on its constructor:

if( Engine::AllOpenGLExtensionsAvailable ) {
        Engine::glGenFramebuffersEXT(1, &rFBO);
        // attaching texture image to created FBO for later blit
        Engine::glFramebufferTexture2DEXT( rFBO, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, this->rTexID, 0 );

… and then I did bind it, but the same crash with the same error was happening, its exactly the same:

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

… call to blit after all of this crashes

I’m new to OpenGL extensions and while searching how texture could be written to some other texture to make permanent alterations of that other texture for later use, I’ve found glBlitFramebufferEXT, but its not working. I could not find something else except PBO alternative which according to people on the Internet is very slow.

What is the best way to draw one texture or a part of it onto another one making that other texture changes permanent?