Results 1 to 9 of 9

Thread: Line Cap for Polygon border lines

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2007
    Location
    Bangalore, India
    Posts
    5

    Line Cap for Polygon border lines

    I want to draw border line of a filled polygon in different color.

    I've used the following code.

    <code>
    glLineStipple (stipple_factor, stipple_pattern);
    glEnable (GL_LINE_STIPPLE);

    glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);

    glVertexPointer (2, GL_FLOAT, 0, vertex);
    glDrawArrays (mode, 0, vertex_count);

    glDisable (GL_LINE_STIPPLE);
    </code>

    By the above code, i'm getting the border line. but the edges of the border line have inappropriate line caps. The lines end directly at the vertices. As a consequence with line widths > 1
    there are visible gaps between the edges if the angle is <> 180 degrees.

    Can you suggest me how to overcome this situation? is there any way to use square, circle or triangle cap like in Microsoft Windows GDI+.

  2. #2
    Senior Member Regular Contributor
    Join Date
    Dec 2007
    Location
    Brighton, UK
    Posts
    161

    Re: Line Cap for Polygon border lines

    One *very* dirty way would be to draw the polygon a bit enlarged, specifying the border color you want ( & disable for this the depth writes if necessary). Afterwards draw the polygon on top of it, at it's normal size & color. & there you go, you have it!

  3. #3
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: Line Cap for Polygon border lines

    hmmm, I have noticed this problem a long time ago, but it did not trouble me. Maybe you can draw vertices as points to make a kind of cap.

    babis> I don't think it is possible with your technique (or it is a bit complicated), you can do the same just drawing lines directly after drawing the mesh in fill mode and using a polygon offset. With GL_LINE_STIPPLE you can specify a line pattern.

  4. #4
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: Line Cap for Polygon border lines

    Here is an opensource vector graphic lib.
    You may want to have a look at their GL backend.
    http://cairographics.org/OpenGL/

  5. #5
    Senior Member Regular Contributor
    Join Date
    Dec 2007
    Location
    Brighton, UK
    Posts
    161

    Re: Line Cap for Polygon border lines

    oops yes it's a bit complicated now that I thought of it, forget what I said!

  6. #6
    Junior Member Newbie
    Join Date
    Apr 2007
    Location
    Bangalore, India
    Posts
    5

    Re: Line Cap for Polygon border lines

    Hi dletozeun,

    Thanks for your guidance. It solved my problem when I draw the Vertices as Points with glPointSize () setting equivalent to the Line Width.

  7. #7
    Senior Member OpenGL Guru zed's Avatar
    Join Date
    Nov 2010
    Posts
    2,466

    Re: Line Cap for Polygon border lines

    a better way is to make your own line function that draws them as quads

    VEC3 qA = cameras_position - p0;
    VEC3 wA = ( p1 - p0 );
    VEC3 nA = return_VECTORS_normal(CROSSPRODUCT( qA,wA )) * line_width;

    thus the 4 verts of the quad are p0+nA,p0-nA,p1+nA,p1-nA,

    this quad is only for a single line
    but for your polygon
    what u want to do is string multiple lines together, adding a triangle if the angle between the joins > 180degrees

  8. #8
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: Line Cap for Polygon border lines

    zed, your technique will require more work to make rounded edges.

  9. #9
    Senior Member OpenGL Guru zed's Avatar
    Join Date
    Nov 2010
    Posts
    2,466

    Re: Line Cap for Polygon border lines

    well theyre sort of round, as theres no breaks in the lines, if u want perfect round corners then u will need to tesselate the triangle at the corner into lotsa triangles, eg like a GL_TRIANGLE_FAN

    had a go at the rounded points, yes Zbuffer a lot more work (+ its still not 100%), i think ill stick to the single triangle



    btw single triangle, if the lines arent that wide (+ the OPs ones wont be i think) youll hardly notice the difference + also texturing them is a lot simplier

Similar Threads

  1. Calculating polygon lines
    By Tiberiu in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 09-27-2010, 06:55 AM
  2. how to draw a polygon with different border color
    By aykutucar in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 07-27-2003, 03:28 PM
  3. how do I make a line reflect off the border?
    By cali in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 09-29-2001, 12:35 AM
  4. hidden line removal (by lines, not polygon)
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 10-30-2000, 08:52 AM
  5. hidden line removal (by lines, not polygon)
    By in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 10-25-2000, 09:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean