Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 735407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:29:10+00:00 2026-05-14T07:29:10+00:00

I’m trying to perform hidden line removal using polygon offset fill. The code works

  • 0

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[1]);
  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);
}

Setup FBO’s

void setupRC()
{
  setupTextures();
  glGenFramebuffersEXT(2, framebufferID);

  glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebufferID[0]);
  glGenRenderbuffersEXT(1, &renderbufferID);
  glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, renderbufferID);
  glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT32, fboWidth, fboHeight);
  glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, renderbufferID);
  glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, renderTextureID[0], 0);
  GLenum fboStatus = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
  if(fboStatus != GL_FRAMEBUFFER_COMPLETE_EXT){
    fprintf(stderr, "FBO #1 Error!");
  }
  glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebufferID[1]);
  glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, renderTextureID[1], 0);
  fboStatus = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
  if(fboStatus != GL_FRAMEBUFFER_COMPLETE_EXT){
     fprintf(stderr, "FBO #2 Error!");
  }
  glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
}

Setup textures

void setupTextures(void)
{
  glGenTextures(2, renderTextureID);

  for (GLint i = 0; i < 2; i++){
    glBindTexture(GL_TEXTURE_2D, renderTextureID[i]);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    // this may change with window size changes
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, fboWidth, fboHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
  }
  glBindTexture(GL_TEXTURE_2D, 0);
}

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T07:29:10+00:00Added an answer on May 14, 2026 at 7:29 am

    The problem is that I was rendering to a FBO without a depth attachment. Setting up the second FBO the same as the first gave the correct results.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 442k
  • Answers 442k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer No, you can't (easily) access your Cocoa objects and classes… May 15, 2026 at 5:54 pm
  • Editorial Team
    Editorial Team added an answer Looks like you need to pass your credentials when calling… May 15, 2026 at 5:54 pm
  • Editorial Team
    Editorial Team added an answer You could start by following the installation guide for GuicePlugin… May 15, 2026 at 5:54 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.