Results 1 to 6 of 6

Thread: Lines one pixel too short

  1. #1

    Lines one pixel too short

    Hi,

    i am rather new to OpenGL and got already stuck in a (minor?) problem. I wanted to investigate something line related and found that my lines are all one pixel too short, even simple ones like the following.

    The viewport is set up with gluOrtho2D.
    This
    Code :
          glColor3ub(255, 255, 255);
          glBegin(GL_POINTS);
          glVertex2i(200,30);
          glVertex2i(300,30);
          glVertex2i(300,20);
          glVertex2i(200,20);
          glEnd();
     
          glColor3ub(255, 0, 0);
          glBegin(GL_LINES);
          glVertex2i(200,30);
          glVertex2i(300,30);
          glVertex2i(300,20);
          glVertex2i(200,20);
          glEnd();
    renders to http://evilazrael.net/bilder2/support/opengl_lines.png
    There should be no white points visible, but they are. Any idea why this happens? I thought of integer -> float conversion errors, but they should affect both and i tried with floats, too.

    Any idea how to render this correct?

    Thanks in advance

  2. #2
    Senior Member OpenGL Pro Ilian Dinev's Avatar
    Join Date
    Jan 2008
    Location
    Watford, UK
    Posts
    1,294

    Re: Lines one pixel too short

    Isn't this the standard?
    I.e when you draw a triangle, you don't want the rightmost pixels drawn, as an adjacent triangle should be filling there.

  3. #3
    Member Contributor
    Join Date
    Jan 2001
    Posts
    82

    Re: Lines one pixel too short

    That is standard practice to prevent drawing the pixel twice when drawing wireframe polygons. It can be annoying when drawing a single line, but it is something you'll have to live with. Or you can write your own line drawing code.

  4. #4

    Re: Lines one pixel too short

    First thanks for the answers.

    Both answers have something that makes sense but they are not complete reasonable. If you check the Vertices, youŽll see that the second line is drawn from right to left, or at least the Vertices are given in that order.

    - Why should opengl prefer the right side? I could draw adjacent triangles on the left side.
    - Shortening lines by one pixel is a rather bad speed optimization in my eyes, painting one pixel less for an inaccurate result is not very reasonable. Especially what is the least painful way to correct this?

    On a line with "round caps" i can put a smoothed point at the end, but on a line with "butt caps", how can i correct this?

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

    Re: Lines one pixel too short

    Why ? because it is correct.
    http://www.opengl.org/documentation/....1/node47.html

    If pixel have the risk of being written multiple times on adjacent lines, it will mess up the blended primitives completely.

  6. #6
    Member Contributor
    Join Date
    Jan 2001
    Posts
    82

    Re: Lines one pixel too short

    Most GUI implementations do this now. I remember how frustrated this made me when I came over to Windows from the Mac. I was used to QuickDraw drawing all pixels from the start point to the end point. Now it is just pretty much expected.

Similar Threads

  1. Replies: 3
    Last Post: 06-15-2015, 03:48 AM
  2. Single Pixel Lines in Textures Shimmer
    By coolguyclay in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 10-28-2008, 12:32 PM
  3. two short questions
    By Vexator in forum OpenGL: Advanced Coding
    Replies: 6
    Last Post: 08-01-2005, 11:29 AM
  4. lines not visible < 1 pixel
    By in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 01-26-2004, 03:33 AM
  5. Replies: 4
    Last Post: 09-02-2002, 08:05 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