How to hide the backside of the GL_LINE

This topic contains 6 replies, has 3 voices, and was last updated by  Gordon 7 years, 3 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #30181

    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
    #34023

    Gordon
    Moderator

    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?

    #34024
    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.
    #34025

    Gordon
    Moderator

    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.

    #34026

    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.

     

     
    #34027

    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.

    #34028

    Gordon
    Moderator

    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

Viewing 7 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic.