How to hide the backside of the GL_LINE

I am drawing one surface on the current scene. Then on the suface, I draw a line with normal the same as the surface but different color. Then I rotate the two targets at the same time. I usedgl


Enable(GL_CULL_FACE);
glCullFace(GL_FRONT);
glEnable(GL_DEPTH_TEST);  


So when the surface is rotating, it only shows me the front face. However, the line is still there when it rotated to the far side with a black line. I am wondering how to hide this line when it is rotating away with its back side. (see the attached image)

Thank you very much,

Renaissance

I’m afraid you can’t do face culling in OpenGL without a face so this doesn’t work with GL_LINEs. You will have to find another way of culling the lines, I’m afraid.





What kind of scene are you drawing in this way?

Thank you for your reply, Gordon.

 

My application needs sevearl crosses on a rotating closed 3D surface as special indictors. I thought I just need to use GL_LINE to make the cross and it is done. However, the visible backside of the lines adds black noise when the crosses are on the other side of the surface.

If you are able to draw lines then it’s probably going to be quite easy to render polygons with a textured icon or similar as a marker. The benefit of this is that these polygons will get face culled. Be careful of depth fighting issues.





Otherwise you are going to have to find some way of keeping track of which ploys are facing which way.


It seems that I could not get this issue solved and I am trying to use other method to construct the marker, as you suggested, a polygon.

 

Thank you very much, Gordon.

 

 

An alternative might be to give the vertices normals (the same for both endpoints), transform the normals correctly in the vertex shader and then set alpha 0 to zero in pixel shader if the transformed normal points into the negative z direction.



After reading Martin's suggestion, I've considered this further and think that there maybe a way to do something in the vertex shader. If you have normals that are pointing in the direction that your polygon is facing it should be possible to test whether these are facing away from the camera. If the vertices for a line fail the test then they can be transformed to (0,0,0) and the graphics core will cull them away before reaching the fragment processing step and incurring the cost of fragment processing and blending.

Unfortunately, if one end of the line passes and one end fails (say if one end is in front of the camera and one end is behind) then this system will produce strange results.
Gordon2010-07-07 09:54:19