Part of scene only visible when rendered on screen, but not on invisible FBObject

Hello

I’m trying to simulate a camera with radial distortion. My current attempt is to render the scene first on an invisible Framebufferobject to create a texture and then to warp the texture by mapping it on a triangle mesh.

Here is my creation of the FBO so far:


GLuint FramebufferName = 0;
  glGenFramebuffers(1, &FramebufferName);
  glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName);

  GLuint renderedTexture;
  glGenTextures(1, &renderedTexture);

  glBindTexture(GL_TEXTURE_2D, renderedTexture);

  glTexImage2D(GL_TEXTURE_2D, 0,GL_RGB, w_, h_, 0,GL_RGB, GL_UNSIGNED_BYTE, 0);

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


  // The depth buffer
  GLuint depthrenderbuffer;
  glGenRenderbuffers(1, &depthrenderbuffer);
  glBindRenderbuffer(GL_RENDERBUFFER, depthrenderbuffer);
  glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, w_, h_);
  glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthrenderbuffer);

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

  GLenum DrawBuffers[2] = {GL_COLOR_ATTACHMENT0};
  glDrawBuffers(1, DrawBuffers);

  if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE){
    ROS_INFO("framebuffer fail"); assert(false);
  }

  glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName);


To check if my code works, I used some triangles


    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0.0f, w_, h_, 0.0f, -1.0f, 1.0f);

    glViewport(0,0,w_,h_);

    glEnable(GL_DEPTH_TEST);


    glBegin(GL_TRIANGLES);
    glColor3f(1,0,0); glVertex3f(0,0,0);
    glColor3f(0,1,0); glVertex3f(0,h_,0);
    glColor3f(0,0,1); glVertex3f(w_,0,0);
glEnd();

And here is my rendering of the create


  glBindFramebuffer(GL_FRAMEBUFFER, 0); //  draw again on visible Framebuffer
  glEnable(GL_TEXTURE_2D);
  glBindTexture(GL_TEXTURE_2D, renderedTexture);
  glColor3f(1,1,1);

  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glOrtho(0.0f, w_, h_, 0.0f, 0.0f, 1.0f);

  glViewport(0,0,w_,h_);


  glBegin(GL_QUADS);
  glTexCoord2f(0,1);
  glVertex3f(0,0,0);
 ...

This works nicely so that there is at least no major error (I hope).

The problem arises as soon as I try to render my scene. If I just use the normal Framebuffer (glBindFramebuffer(GL_FRAMEBUFFER, 0);), it renders perfectly, but if I render onto the invisible FBO, I only get a black image. I create my own GL_Projection matrix from values I computed from OpenCV but since I am able to use it with the normal Framebuffer, I don’t know how this could cause a problem.

I don’t have much experience with OpenGL so that I don"t know how I can debug the code.
Has anybody an idea what could be the reason for this behavior?

Nikolas