FBO... what the problem?

Started by
4 comments, last by smitty1276 17 years, 7 months ago
Here I post my draw function in its entirety (not big). I was using this to debug a little shader. It is supposed to draw a few lines to an FBO texture, then bind the texture, enable the shader, and draw to a quad. If I don't put the bRendered check around the FBO block, the FBO attemps to render every frame, and for some reason nothing shows up. With the check in place, it draws the texture on the first pass, and works (but I want to draw every pass). Does anyone see what might be causing this? As with most of these problems, I'm sure it's something really stupid...
    static bool bRendered = false;
    //if (!bRendered)    
    if (true)
    {
        // Render to FBO
        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
        {
            // Store current viewport, and set to texture dimensions...
            int vp[4];
            glGetIntegerv(GL_VIEWPORT, vp);       
            glViewport(0, 0, 1024, 1024);

            glMatrixMode(GL_MODELVIEW);
            glLoadIdentity();
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
            
            glColor3f(0.0, 1.0, 0.0);
            glBegin(GL_LINES);
                glVertex3f(0.2, 0.2, 0.5); glVertex3f(0.8, 0.2, 0.5);
                glVertex3f(0.2, 0.5, 0.5); glVertex3f(0.8, 0.5, 0.5);
                glVertex3f(0.2, 0.8, 0.5); glVertex3f(0.8, 0.8, 0.5);
                glVertex3f(0.2, 0.8, 0.5); glVertex3f(0.2, 0.2, 0.5);
                glVertex3f(0.5, 0.8, 0.5); glVertex3f(0.5, 0.2, 0.5);
                glVertex3f(0.8, 0.8, 0.5); glVertex3f(0.8, 0.2, 0.5);
            glEnd();			
            glViewport(vp[0], vp[1], vp[2], vp[3]); // restore viewport
        }
        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
        bRendered = true;
    }

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glEnable(GL_TEXTURE_2D);
    glEnable(GL_TEXTURE0);
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, fboTexture1);
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);    

    bool result = false;
    result = shaderMgr->EnableProgram("Blur1");    
    {
        result = shaderMgr->SetSampler2D("tex", 0);
        result = shaderMgr->SetUniformFloat1("texSize", 1024.0);

        glBegin(GL_QUADS);			
            glTexCoord2f(0.0, 0.0); glVertex3f(0.0, 0.0, 0.5);
            glTexCoord2f(1.0, 0.0); glVertex3f(1.0, 0.0, 0.5);
            glTexCoord2f(1.0, 1.0); glVertex3f(1.0, 1.0, 0.5);
            glTexCoord2f(0.0, 1.0); glVertex3f(0.0, 1.0, 0.5);
        glEnd();
    }
    shaderMgr->DisableProgram();

    glFlush();
    glutSwapBuffers();

Advertisement
You forgot to "unbind" the texture you render to.
if (time() == $) { $ = 0; }
I called glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0)... Does the attached texture not get bound and unbound with the FBO itself? Or are you referring to the bottom where it is actually rendered?

How would that affect the FBO drawing, which isn't using any textures?
Quote:Does the attached texture not get bound and unbound with the FBO itself?


No. You must do it yourself. Just bind some other texture (or none) before rendering to the FBO. You cannot use a texture that you're rendering to.
if (time() == $) { $ = 0; }
I'm confused about what you are saying... The FBO doesn't use any textures except for the ones that are attached to it. Those aren't bound, they are simply attached and drawn to when the FBO is bound.

Any textures used when rendering the quad at the bottom shouldn't affect the FBO at all, since it isn't using any textures (except for the ones that are attached to it).

I'm confused about what you are suggesting to be the problem. When you say "You cannot use a texture that you're rendering to", what do you mean? The FBO is unbound, and then the attached texture is used to draw the quad.
Oh, okay. I see what you mean. You meant that the attached texture was still bound... I'm not sure how I didn't get that. :-)

Thanks for the help.

This topic is closed to new replies.

Advertisement