OpenGL Core 3.2 framebuffer rendering black on Mac OSX

Matthew Clark
  • OpenGL Core 3.2 framebuffer rendering black on Mac OSX Matthew Clark

    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^^)

  • 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);
    

Tags
opengl c++ macos
Related questions and answers
  • ); 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, m_FBOWidth, m_FBOHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); glBindTexture(GL...() { ///////////////////////////////////////// // Render to FBO glClearColor(0, 0, 0.2f,0); glBindFramebuffer(GL_FRAMEBUFFER, fbo_id); glViewport(0, 0, m_FBOWidth, m_FBOHeight); glClear(GL_COLOR_BUFFER_BIT

  • I'm using SDL &amp; openGL to render a tile-map. The issue is that the tile-map rendering is extremely messed up, and I'm just a bit unsure what I'm doing wrong exactly. It should just be the first tile being rendered, but I'm getting a blurred mess :S. My rendering code: glBindTexture(GL_TEXTURE_2D, texture); float texscale = 1.0f / (float)tileWidth; sourceX = sourceX / (float)tileSheetWidth..., bmask, amask); SDL_BlitSurface(LoadedImage, NULL, image, NULL); glGenTextures(1, &amp;texture); glBindTexture(GL_TEXTURE_2D, texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL

  • (1, &amp;shaderTexture[0]); // Get A Free Texture ID ( NEW ) glBindTexture (GL_TEXTURE_1D, shaderTexture[0]); // Bind This Texture. From Now On It Will Be 1D...); // Set The Color Of The Model ( NEW ) // ORIGINAL DRAWING CODE //Draw the model as an interpolation between the two frames glBegin(GL_TRIANGLES); for(int i = 0; i... NEHE'S TUT glBegin (GL_TRIANGLES); // Tell OpenGL What We Want To Draw for(int i = 0; i &lt; numTriangles; i++) { MD2Triangle* triangle

  • ); glDisableClientState( GL_COLOR_ARRAY ); glBindBuffer( GL_ARRAY_BUFFER, 0 ); glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 ); } Back to the Vertex Array Object though. My code for creating the Vertex... for( int n = 0; n &lt; vShaderArgs.size(); n ++ ) { glEnableVertexAttribArray(n); glVertexAttribPointer( n, vShaderArgs[n].nFieldSize, GL_FLOAT, GL_FALSE... onscreen, in the shape of the terrain rectangle, but there are no regular lines etc. Here's the code I use for rendering: void ShaderProgram::Draw() { using namespace AntiMatter; if( ! m

  • I'm trying to map a brick texture on the edge of a fountain and I'm using gluDisk for that. How can I make the right coordinates for the disk? My code looks like this and I have only found a function... // also drawing more here... // stone texture glBindTexture(GL_TEXTURE_2D, texIDs[0]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glPushMatrix

  • ; glGenTextures(1, &amp;thisIsMyTexture); temporarySurface = loadImage("theimagetomytexture.png"); glBindTexture(GL_TEXTURE_2D,thisIsMyTexture); glTexImage2D(GL_TEXTURE_2D, 0, 4, temporarySurface->w, temporarySurface->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, temporarySurface->pixels); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); ...and the drawing code itself. glBindTexture(GL_TEXTURE_2D,thisIsMyTexture); glBegin( GL_QUADS ); glTexCoord2f(0.0f, 0.0f); glVertex3f(0.0f, 0.0f, 1.0f); glTexCoord2f(1.0f

  • _Quit(); return -1; } glGenTextures(1, &amp;image); glBindTexture(GL_TEXTURE_2D, image); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT...I'm learning C++, and I'm writing my first OpenGL program. Unfortunately, it seems to be defaulting to Software Rendering (CPU uses bounces, GPU uses stays at 1%). I'm using SDL as the Windowing...; break; } } glClear(GL_COLOR_BUFFER_BIT); glLoadIdentity(); glTranslatef(200.0f, 200.0f, 0.0f); glRotatef(x,0.0f,0.0f, 1.0f

  • ;fileName ) { SDL_Surface *image = IMG_Load( fileName.c_str() ); SDL_DisplayFormatAlpha(image); unsigned object(0); glGenTextures(1, &amp;object); glBindTexture(GL_TEXTURE_2D, object); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_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_RGBA, image -> w, image -> h, 0, GL_RGBA, GL_UNSIGNED_BYTE, image -> pixels); //Free surface

  • I'm having some problems porting my D3D code to OpenGL ES. I have a Graphics Device class that encapsulates all rendering commands. The code below is in an ObjC++ file. The problem code is the called to get the render buffer width and height. It doesn't actually return any value in the w or h GLints. It should be noted that the code below is from an older iPhone project, and it works there. Am I missing something really stupid? Checking the framebuffer status returns a value of complete, since OpenGL ES seems quite happy to initialize a depth buffer with the garbage w and h values I pass

Data information