Results 1 to 2 of 2

Thread: Impossible to create rendertexture. (failed to link the target texture to the FBO)

  1. #1
    Member Contributor
    Join Date
    Oct 2015
    Posts
    60

    Impossible to create rendertexture. (failed to link the target texture to the FBO)

    Hi, when I try to link my stencil texture to the FBO it fails.
    I create the target texture here :
    Code :
    // Initialize the texture
                glCheck(glBindTexture(GL_TEXTURE_2D, m_texture));
                if (!stencilTexture && !depthTexture) {
                    glCheck(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_actualSize.x, m_actualSize.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL));
                    glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, m_isRepeated ? GL_REPEAT : GL_CLAMP_TO_EDGE));
                    glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, m_isRepeated ? GL_REPEAT : GL_CLAMP_TO_EDGE));
                    glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, m_isSmooth ? GL_LINEAR : GL_NEAREST));
                    glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, m_isSmooth ? GL_LINEAR : GL_NEAREST));
     
                } else if (depthTexture) {
                    glCheck(glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL));
     
                } else {
                    glCheck(glTexImage2D(GL_TEXTURE_2D, 0, GL_STENCIL_INDEX16, width, height, 0, GL_STENCIL, GL_FLOAT, NULL));
                }

    And then I pass it to the FBO.
    Code cpp:
    // Create the texture
                if(!m_texture.create(width, height))
                {
                    err() << "Impossible to create render texture (failed to create the target texture)" << std::endl;
                    return false;
                }
                // We disable smoothing by default for render textures
                setSmooth(false);
                if (stencilTexture) {
                    if (!m_stencilTexture.create(width, height, false, true)) {
                        err() << "Impossible to create render texture (failed to create the target stencil texture)" << std::endl;
                        return false;
                    }
                }
                if (depthTexture) {
                    if (!m_depthTexture.create(width, height, true, false)) {
                        err() << "Impossible to create render texture (failed to create the target depth buffer texture)" << std::endl;
                        return false;
                    }
                }
                // Create the implementation
                delete m_impl;
                if (priv::RenderTextureImplFBO::isAvailable())
                {
                    // Use frame-buffer object (FBO)
                    m_impl = new priv::RenderTextureImplFBO;
                }
                else
                {
                    // Use default implementation
                    m_impl = new priv::RenderTextureImplDefault;
                }
     
                // Initialize the render texture
                if (!m_impl->create(width, height, settings, m_texture.m_texture, m_depthTexture.m_texture, m_stencilTexture.m_texture))
                    return false;

    Code :
    // Create the context
                    m_context = new Context(settings, width, height);
                    // Create the framebuffer object
                    GLuint frameBuffer = 0;
                    glCheck(glGenFramebuffersEXT(1, &frameBuffer));
                    m_frameBuffer = static_cast<unsigned int>(frameBuffer);
                    if (!m_frameBuffer)
                    {
                        err() << "Impossible to create render texture (failed to create the frame buffer object)" << std::endl;
                        return false;
                    }
                    glCheck(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_frameBuffer));
                    // Create the depth buffer if requested
                    if (settings.depthBits > 0)
                    {
                        GLuint depth = 0;
                        glCheck(glGenRenderbuffersEXT(1, &depth));
                        m_depthBuffer = static_cast<unsigned int>(depth);
                        if (!m_depthBuffer)
                        {
                            err() << "Impossible to create render texture (failed to create the attached depth buffer)" << std::endl;
                            return false;
                        }
                        glCheck(glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, m_depthBuffer));
                        glCheck(glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, width, height));
                        glCheck(glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_depthBuffer));
                    }
                    if (settings.stencilBits > 0) {
                        GLuint stencil = 0;
                        glCheck(glGenRenderbuffersEXT(1, &stencil));
                        m_stencilBuffer = static_cast<unsigned int>(stencil);
                        if (!m_stencilBuffer) {
                            err() << "Impossible to create render texture (failed to create the attached stencil buffer)" << std::endl;
                            return false;
                        }
                        glCheck(glBindRenderbufferEXT(GL_RENDERBUFFER_EXT,m_stencilBuffer));
                        glCheck(glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_STENCIL_INDEX, width, height));
                        glCheck(glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_stencilBuffer));
                    }
                    if (stencilTextureId != 0) {
                        glCheck(glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, depthTextureId, 0));
                        glCheck(glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_TEXTURE_2D, stencilTextureId, 0));
                    }
                    if (depthTextureId != 0 && stencilTextureId == 0) {
                        glCheck(glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, depthTextureId, 0));
                    }
                    // Link the texture to the frame buffer
                    glCheck(glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, textureId, 0));
                    // A final check, just to be sure...
                    if (glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) != GL_FRAMEBUFFER_COMPLETE_EXT)
                    {
                        glCheck(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0));
                        err() << "Impossible to create render texture (failed to link the target texture to the frame buffer)" << std::endl;
                        return false;
                    }
                    return true;

    What's wrong with this ?

  2. #2
    Senior Member OpenGL Lord
    Join Date
    Mar 2015
    Posts
    6,674
    What exactly fails? And why are you using an extension from a decade-and-a-half ago instead of the core functionality that's been around since GL 3.0?

    Also, it should be noted that pretty much no hardware supports using separate textures for depth and stencil. So if you use just depth, you'll probably be fine. If you use just stencil, you'll probably be fine. But you shouldn't try to use both at once as separate textures. This is why depth/stencil formats exist.

Similar Threads

  1. Why failed to create kernel?
    By SHU_Leo in forum OpenCL
    Replies: 1
    Last Post: 04-05-2012, 11:09 AM
  2. Replies: 0
    Last Post: 03-28-2010, 08:39 PM
  3. Failed to create opengl
    By imported_Len in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 11-22-2005, 07:18 PM
  4. How can I check wether OGL failed to create a texture?
    By B_old in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 07-20-2003, 11:32 AM
  5. Replies: 11
    Last Post: 03-06-2002, 05:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean