0

I encountered a problem when working on visualizing scientific 3d models. The task is to render a model filled with a color and a wireframe overlay. This works fine for models that are solids with a closed surface.

Problem #1:

I have several polygons without knowing anything about their visibility/orientation before rendering. To make sure all polygons are displayed correctly, I first draw all polygons clockwise and then counterclockwise, same for the wireframe overlay. This seems to work for some models, but not for all models.

Some of my models end up looking like this.

Problem #2:

I don't know if this is related to Problem #1, but PolygonOffset makes some edges look bad, probably because of the mixed orientation of the model polygons: Wireframe edges

**The code: **

Due to limitations given to me, I have to write the code in Fortran 77. Nevertheless, the OpenGL calls stay the same. This is the code for drawing a model:

c     Draw object 
      do 10 i=1,2
c       Select correct orientation
        if(ccw) then 
            call glFrontFace(GL_CCW)
        else
            call glFrontFace(GL_CW)
        endif

c       Set object color
        call glColor3f(1.0,1.0,1.0)

c       Set polygon mode to fill
        call glPolygonMode(GL_FRONT_AND_BACK,GL_FILL)

c       Set polygon offset and enable offset (float for glPolygonOffset,
c       otherwise it won't work)
        call glPolygonOffset(1.0,2.0)
        call glEnable(GL_POLYGON_OFFSET_FILL)

c       Draw object
        call glCallList(lindex)

c       Disable polygon offset
        call glDisable(GL_POLYGON_OFFSET_FILL)

c       Reverse orientation
        ccw = .not. ccw
 10   continue

c     Draw Wireframe onto Object
      do 20 i=1,2
c       Select correct orientation
        if(ccw) then 
            call glFrontFace(GL_CCW)
        else
            call glFrontFace(GL_CW)
        endif

c       Set object color
        call glColor3f(0.0,0.0,0.0)

c       Set polygon mode to wireframe
        call glPolygonMode(GL_FRONT_AND_BACK,GL_LINE)

c       Draw object
        call glCallList(lindex)

c       Set polygon mode to fill
        call glPolygonMode(GL_FRONT_AND_BACK,GL_FILL)

c       Reverse orientation
        ccw = .not. ccw
 20   continue

Other Information: Culling is enabled, Depth Function is GL_LESS.

  • Please edit slightly so this in the form of a question so we can better answer. – demongolem Oct 20 '14 at 19:10
  • It seems like you want to draw a solid object and then a wireframe on top of it, using GL_POLYGON_OFFSET_FILL. You can achieve that in a simpler way, by doing glDisable(GL_DEPTH_TEST) before drawing wireframe, and glEnable(GL_DEPTH_TEST) after that, and you won't need that GL_POLYGON_OFFSET_FILL at all. Also, if you do glDisable(GL_CULL_FACE) before drawing, you can get rid of this ugly glFrontFace(GL_CCW)/glFrontFace(GL_CW) juggling. – pelya Oct 20 '14 at 19:33
  • Thank you for your answer. Disabling the Depth test for Wireframe drawing doesn not fix the problem, cause now all Wireframe lines are displayed on every model, but I only want to see the visible wireframe lines. – user3413372 Oct 20 '14 at 20:33

2 Answers2

0

If using CW and CCW why render with GL_FRONT_AND_BACK. Surely just use GL_FRONT. glOffset has it's limitations, so some edges may be offsetting into your model, hence the ragged edges on some only, it all depends on the side they are on. Looking at X2d4K I get the impression the model itself may include 'wrongly' oriented surfaces, so preferbaly try doing this without backface culling. The depth buffer should then have no problem hiding any change in orientation.

Gavin Simpson
  • 2,766
  • 3
  • 30
  • 39
0

I found the reason for my problems: I used a 16 bit Depth Buffer, switching to 32 bit eliminates all the Problems.