How can I successfully perform hidden line removal after pass through FBO?

Posted by Brett on Stack Overflow See other posts from Stack Overflow or by Brett
Published on 2010-03-31T12:33:00Z Indexed on 2010/04/02 0:53 UTC
Read the original article Hit count: 407

Filed under:
|
|

Hi All,

I'm trying to perform hidden line removal using polygon offset fill. The code works perfectly if I render directly to the window buffer but fails to draw the lines when passed through a FBO as shown below

alt text

The code I use to draw the objects

void drawCubes (GLboolean removeHiddenLines)
{
  glLineWidth(2.0);
  glPushMatrix();
    camera.ApplyCameraTransform();
    for(int i = 0; i < 50; i ++){
    glPushMatrix();
      cube[i].updatePerspective();
      glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
      glColor3f(1.0,1.0,1.0);
      cube[i].draw();
      glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

      if(removeHiddenLines){
          glEnable(GL_POLYGON_OFFSET_FILL);
          glPolygonOffset(1.0, 1.0);
          glColor3f(1.0, 0.0, 0.0);  //fill polygons for hidden line removal
          cube[i].draw();
          glDisable(GL_POLYGON_OFFSET_FILL);
      }
    glPopMatrix();
  }
  glPopMatrix();
}

For this example, the first pass involves rendering to both the window buffer and a FBO.

void firstPass()
{
  glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  glViewport(0, 0, fboWidth, fboHeight);

  glEnable(GL_DEPTH_TEST);
  glDisable(GL_TEXTURE_2D);
  drawParticleView(GL_TRUE);
  glDisable(GL_DEPTH_TEST);

  glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebufferID[0]);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  glViewport(0, 0, fboWidth, fboHeight);

  glEnable(GL_DEPTH_TEST);
  glDisable(GL_TEXTURE_2D);
  drawParticleView(GL_TRUE);
  glDisable(GL_DEPTH_TEST);
}

Second pass renders FBO back to window buffer.

void secondPass()
{
  glEnable(GL_TEXTURE_2D);

  glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
  glBindTexture(GL_TEXTURE_2D, renderTextureID[0]);

  glViewport(fboWidth, 0, fboWidth, fboHeight);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();

  glBegin(GL_QUADS);
    glTexCoord2i(0, 0);
    glVertex2f(-1.0f, -1.0f);
    glTexCoord2i(1, 0);
    glVertex2f(1.0f, -1.0f);
    glTexCoord2i(1, 1);
    glVertex2f(1.0f, 1.0f);
    glTexCoord2i(0, 1);
    glVertex2f(-1.0f, 1.0f);
  glEnd();

  glDisable(GL_TEXTURE_2D);
}

I don't understand why the two views wouldn't be the same? Am I missing something (obviously I am)?
Thanks

© Stack Overflow or respective owner

Related posts about opengl

Related posts about fbo