Multiple framebuffer objects

Hi guy!

I have a few questions about fbos, i’ve tried to search but did not find what is was looking for.

At the moment i am trying to use 2 fbos. I have bound two textures to the first fbo at GL_COLOR_ATTACHMENT0 and GL_COLOR_ATTACHMENT1. But when i bind a texture at GL_COLOR_ATTACHMENT0 in the other fbo the rendering goes blank.

Is this supposed to happened? Then i bind the last texture to GL_COLOR_ATTACHMENT2 in the second fbo the rendering is not affected, but as i have understood, the fbos should be separate and not display this kind of behaviour.

Why are you changing the attachment during rendering? Normally, you would assign color attachments to the fbo at initialization and then when rendering, you would redirect the rendering through glDrawBuffers function passing it the attachment you want to draw to.

To be of more help, could u show how you are doing it currently?

Sorry for not being clear enough.

I am not changing the attachments during rendering, i do all the assigning at the fbo initiations, and my problem still persists.

My initiation code for the first fbo:


    glGenFramebuffers(1, &frameBufferMainId);
    glBindFramebuffer(GL_FRAMEBUFFER, frameBufferMainId);

    GLuint depthBuffer;

    glGenRenderbuffers(1, &depthBuffer);
    glBindRenderbuffer(GL_RENDERBUFFER, depthBuffer);
    glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH_COMPONENT,1000,800);

    glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_RENDERBUFFER, depthBuffer);


    glGenTextures(1,&mainColorTextureId);

    glBindTexture(GL_TEXTURE_2D,mainColorTextureId);
    glTexImage2D(GL_TEXTURE_2D,0,GL_RGB32F,1000,800,0,GL_RGB,GL_UNSIGNED_BYTE,NULL);

    glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,mainColorTextureId,0);

    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);


    glGenTextures(1,&mainNormalTextureId);

    glBindTexture(GL_TEXTURE_2D,mainNormalTextureId);
    glTexImage2D(GL_TEXTURE_2D,0,GL_RGB32F,1000,800,0,GL_RGB,GL_FLOAT,NULL);

    glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT1,GL_TEXTURE_2D,mainNormalTextureId,0);

    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

    //i attach 2 more textures, but the code is almost identical to the code above, so no point in showing it

And the initiation code for the second fbo:


    glGenBuffers(1, &frameBufferSubId);
    glBindFramebuffer(GL_FRAMEBUFFER, frameBufferSubId);

    glGenTextures(1,&subTextureId);

    glBindTexture(GL_TEXTURE_2D,subColorTextureId);
    glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,1000,800,0,GL_RGB,GL_UNSIGNED_BYTE,NULL);

    //if i remove this line...
    glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,subTextureId,0);

    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);


    glGenTextures(1,&subAmbientOcclusionId);

    glBindTexture(GL_TEXTURE_2D,subAmbientOcclusionTextureId);
    glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,1000,800,0,GL_RGB,GL_UNSIGNED_BYTE,NULL);

    //...and this line the rendering seems to be doing ok
    glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT1,GL_TEXTURE_2D,subAmbientOcclusionTextureId,0);

    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

think you have a typo:


glGenBuffers(1, &frameBufferSubId);

should be:


glGenFramebuffers(1, &frameBufferSubId);

Irl nerdrage. That was the problem! I guess thats what i get for not sleeping properly. Thanks for the help!