Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm trying to get a 2 pass post-processing system going in OpenGL in a cross-platform manor using FBOs. I'm starting the dev on mac OSX (since in the past I've found it the most finicky to get working of windows/linux/osx), I have a toggle to toggle between using the FBO(post-processing) and not. The shaders are working, but it seems the FBO didn't load the texture unit bound to it. The following is the init code for the FBO and it's texture:

glGenTextures(1,&fboimg);
glBindTexture(GL_TEXTURE_2D,fboimg);

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 512, 512, 0,
             GL_RGBA, GL_UNSIGNED_BYTE, 0);
glBindTexture(GL_TEXTURE_2D, 0);


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

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

GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);

switch(status)
    {

        case GL_FRAMEBUFFER_COMPLETE:    cout<<"The fbo is complete\n"<<endl; break;
        case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:    cout<<"GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT\n"<<endl; break;
        case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:    cout<<"GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT\n"<<endl; break;
        case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER:    cout<<"GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER"<<endl; break;
        case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER:    cout<<"GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER"<<endl; break;
    }

if(status != GL_FRAMEBUFFER_COMPLETE)
{
    cout<<"status !=  GL_FRAMEBUFFER_COMPLETE"<<endl;
    GLUtils::checkForOpenGLError(__FILE__,__LINE__);
}
else
{
    //shader and VAO setup for post
    fboSetup = true;
}

Here is the render code:

//start rendering to FBO
if(postFlag&&fboSetup)
{
    glBindFramebuffer(GL_FRAMEBUFFER, fboHandle);

}
glUseProgram(programHandle);

//start rendering scene one way or another
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

glUniformMatrix4fv(mats.projHandle,1,GL_FALSE, glm::value_ptr(mats.projMatrix));
glUniformMatrix4fv(mats.mvHandle,1,GL_FALSE,glm::value_ptr(mats.modelViewMatrix));

//bind to vertex array object
glBindVertexArray(vaoHandle);
//render scene
glDrawArrays(GL_TRIANGLES, 0, 240*3 );

//do post-processing if we have it enabled
if(postFlag&&fboSetup)
{
    glFlush();
    glBindFramebuffer(GL_FRAMEBUFFER, 0);

    glUseProgram(fboProgram);

    glClear(GL_COLOR_BUFFER_BIT);

    glBindTexture(GL_TEXTURE_2D,fboimg);

    glUniform1i(glGetUniformLocation(fboProgram,"sampler0"),fboimg);
    glUniform2f(glGetUniformLocation(fboProgram,"resolution"),512,512);
    glBindVertexArray(vaoFBO);
    glDrawArrays(GL_TRIANGLES, 0, 6);
    glBindTexture(GL_TEXTURE_2D, 0);
}

Tried everything I can think of or find in a FBO tutorial or have read about. I don't get any errors and it returns as complete. (Also I can't seem to get it glTexImage2d a image of size width and height. says invalid values, and if I try to use GL_TEXTURE_RECTANGLE it says invalid enum :-/ but that's for a different question after I just get it working to begin with^^)

share|improve this question

1 Answer 1

up vote 0 down vote accepted

I'm an idiot. Textures 101:

glBindTexture(GL_TEXTURE_2D,fboimg);
glUniform1i(glGetUniformLocation(fboProgram,"sampler0"),fboimg);

should be:

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D,fboimg);
glUniform1i(glGetUniformLocation(fboProgram,"sampler0"),0);
share|improve this answer
    
be sure to mark this answer as accepted when you can. –  Tetrad Jan 4 '12 at 17:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.