How to detect inner and outer faces of a hollow/open 3d object

Hey guys,
I am new to opengl.I have written a basic program to draw a pyramid.And I have used the “zoom-pick-rotate” library from the net to,well,zoom,rotate and pick the sides of the object.But the problem is it helps me only to identify sides,but I want to differentiate between inner and outer surfaces.I currently have no clue how to do that.Help me out guys,

[QUOTE=avpai1992;1279693]Hey guys,
I am new to opengl.I have written a basic program to draw a pyramid.And I have used the “zoom-pick-rotate” library from the net to,well,zoom,rotate and pick the sides of the object.But the problem is it helps me only to identify sides,but I want to differentiate between inner and outer surfaces.I currently have no clue how to do that.[/QUOTE]

It’s not clear what you’re asking here.

An open surface (a surface for which one or more edges belong only to one face, rather than having a face on either side) doesn’t have an “inside” or “outside”.

A closed surface (where every edge of a face is shared with another face) has an inside and an outside (unless it self-intersects, which is a problem all to itself). You can determine whether a point is inside or outside by counting the number of faces which intersect a ray between that point and any point which is known to be outside the surface (e.g. some point outside the surface’s bounding box or convex hull). You can determine which side of a face is inside or outside similarly; by counting the number of intersections with a ray emanating from the face and also considering whether the dot product between the ray’s direction and the face normal is positive or negative.

For a complex mesh, that can be a significant amount of work. So normally you create the topology so that the interior and exterior faces have a specific known winding (clockwise or counter-clockwise). This has the advantage that you can choose to render only interior faces or only exterior faces by using glEnable(GL_CULL_FACE), glCullFace() and glFrontFace(). Similarly, you can apply different material parameters to interior and exterior faces by defining which are the “front” and “back” faces with glFrontFace() and either passing GL_FRONT or GL_BACK to glMaterial() (when using fixed-function lighting) or by testing the gl_FrontFacing variable in the fragment shader (when using a fragment shader).

If you have a closed mesh whose winding is consistent but unknown, you can determine the winding by rendering the mesh (from a viewpoint outside the mesh) twice, once with only front faces rendered and once with only back faces rendered, using an occlusion query (glBeginQuery(GL_ANY_SAMPLES_PASSED)). Whichever pass results in samples being generated is the exterior face (if both passes result in samples being generated, either the mesh isn’t closed, or it self-intersects, or the winding is inconsistent).

I assume that one of the sides of the pyramid is missing, allowing you to see inside?

How about drawing the pyramid twice with face culling reversed the second time (glCullface, glEnable (GL_CULL_FACE)).

I agree. The only way you could ‘pick’ an interior surface would be if you could see it.
The only way you could see an interior surface would be if one of the exterior faces was missing?
Is this the case? If there is some confusion on this issue I recommend drawing the pyramid
twice. First time in red only showing outer faces (use culling to not display back faces). Second
time in green only showing inner faces (culling out front faces).

[QUOTE=Carmine;1279703]I agree. The only way you could ‘pick’ an interior surface would be if you could see it.
The only way you could see an interior surface would be if one of the exterior faces was missing?
Is this the case? If there is some confusion on this issue I recommend drawing the pyramid
twice. First time in red only showing outer faces (use culling to not display back faces). Second
time in green only showing inner faces (culling out front faces).[/QUOTE]

Imagine a pyramid,without its base. That way when we rotate we can see the inner sides.

Imagine a pyramid,without its base. That way when we rotate we can see the inner sides.

So - you are drawing 4 triangles, but you want to be able to identify 8 triangles.
I would draw all of the triangles twice, with the interior triangles a different color from the exterior.
You can use the same vertices, but reverse the winding and the normals (there are other ways).
I would want to get this working correctly before addressing the picking.
When this is done (i.e. it looks right - including the lighting), then all you have to do is add
4 more ‘PushName’ calls to the 4 new interior triangles. Make sense?