Hello Guest

Best approach for "Solid Wireframe" ?

  • 3 Replies
  • 16081 Views
Best approach for "Solid Wireframe" ?
« on: June 16, 2005, 07:27:38 »
Please forgive a newbie.

I'm looking for the correct approach for the effect I'm after. As I'm only starting to learn OpenGL I want to create something simple. For now I'm omitting from my scope anything to do with lighting, textures, etc.

I don't have the code at hand, but I have been able to produce 3D objects as wireframe graphics. I'd like for these objects to now appear solid. I.e. the space inside the lines should be filled with the background colour, and therefore hiding the back edges and any objects further away from the camera.

My inital approach was to draw the shapes of each side in the background colour, then overlay the edges in a foreground colour. The result was very flickery and not at all acceptable.

Can anyone suggest a better approach?

Cheers
JemBot

Re: Best approach for "Solid Wireframe" ?
« Reply #1 on: June 16, 2005, 11:30:39 »
Quote from: "JemBot"

My inital approach was to draw the shapes of each side in the background colour, then overlay the edges in a foreground colour. The result was very flickery and not at all acceptable.

This should work fine. However you're probably seeing depth-fighting because the wireframe and the solid rendering is right on top of each other. Changing the depth test to LEQUAL (or GEQUAL, depending on your zbuffer setup) should fix things. If not, you can use depth offset to nudge the wireframe further towards the camera slightly (glDepthOffset).

Best approach for "Solid Wireframe" ?
« Reply #2 on: July 06, 2005, 02:07:14 »
Thanks OT. This is, in fact, what I was doing. But the result was still nasty. I have long since ditched trying to achieve this effect. I may come back to it.

Best approach for "Solid Wireframe" ?
« Reply #3 on: July 11, 2005, 16:26:20 »
This sounds like a job for...

glPolygonOffset( float factor, float units )

This will add an offset to each fragment's depth value, so you can be sure that one thing will appear infront or behind another.

Here's how i use i to draw a wireframe plot of a data grid:
Code: [Select]

   // draw the filled polygons
   glPolygonMode( GL.GL_FRONT_AND_BACK, GL.GL_FILL );
   glEnable( GL.GL_POLYGON_OFFSET_FILL );
   glPolygonOffset( 1, 1 );
   glColor3f( 0.0f, 0.0f, 0.0f );
   renderData();
   gl.glDisable( GL.GL_POLYGON_OFFSET_FILL );
   
   // draw the wireframe
   glPolygonMode( GL.GL_FRONT_AND_BACK, GL.GL_LINE );
   glColor4fv( colour );
   renderData();