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.