Programming > OpenGL

Best approach for "Solid Wireframe" ?

(1/1)

JemBot:
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

Orangy Tang:

--- 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.
--- End quote ---

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).

JemBot:
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.

Panthro:
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: ---
   // 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();
   
--- End code ---

Navigation

[0] Message Index

Go to full version