Results 1 to 3 of 3

Thread: Problem displaying lines in 2D

  1. #1
    Junior Member Newbie
    Join Date
    May 2007
    Posts
    7

    Problem displaying lines in 2D

    Hi,

    I'm new to openGL and just trying to learn the basics. I'm having trouble with 2D images. I created a little function that displays several lines on the screen in 2D. i.e. I left the z-coordinate of glVertex3f set to 0. What I found is that every time I display the lines at different position on the screen, they change slightly.

    For example, in the following, three lines are drawn on the screen, and depending on the "x" parameter, the location is different.
    glBegin( GL_LINES );
    glVertex3f( 0.0f + x, 0.3f, 0.0f );
    glVertex3f( 0.0f + x, 0.0f, 0.0f );
    glVertex3f( 0.0f + x, 0.3f, 0.0f );
    glVertex3f( -0.05f + x, 0.0f, 0.0f );
    glVertex3f( 0.0f + x, 0.3f, 0.0f );
    glVertex3f( 0.05f + x, 0.0f, 0.0f );
    glEnd();

    Every time I change the value of "x", the image is slightly different. i.e. some of the pixels in the line are drawn a little differently.

    How can I drawn a 2D image such that it looks exactly the same every time it is displayed? I have tried setting up the view with:
    glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT );
    glColor3f(1.0f, 0.85f, 0.35f);
    glMatrixMode (GL_MODELVIEW);
    glLoadIdentity ();

    I have also tried changing these settings but no matter what I do, I still have the same problem.


    THanks!
    George

  2. #2
    Senior Member OpenGL Pro k_szczech's Avatar
    Join Date
    Feb 2006
    Location
    Poland
    Posts
    1,107

    Re: Problem displaying lines in 2D

    What you experience is called subpixel accuracy. It's proper behavior and you cannot disable it. If you want line to look always the same then always increase x by such value that will move the line by exactly 1 pixel. Still there is no guarantee it will work because of floating-point precision limitations.

    If you want to further understand this behavior then just take a piece of paper and draw a grid on it - every grid cell is one pixel on screen.
    Then draw two identical lines half a pixel away from each other - see which "pixels" they go through - it will not be the same shape.

  3. #3
    Junior Member Newbie
    Join Date
    May 2007
    Posts
    7

    Re: Problem displaying lines in 2D

    Hi k_szczech,

    Thanks for your help. Your explanation of subpixel accuracy explanation is excellent. It really helps me understand how it works.

    Thanks,
    George

Similar Threads

  1. Problem with window displaying.
    By thealmightyone in forum OpenGL: Linux
    Replies: 6
    Last Post: 01-22-2009, 10:27 PM
  2. Displaying changing lines in OpenGL
    By cheeyw in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 01-20-2008, 12:29 AM
  3. problem while displaying
    By aus79er in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 03-29-2002, 01:27 PM
  4. Displaying DXF LINEs
    By glMask in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 07-15-2001, 07:26 PM
  5. Displaying Multiple Lines of Text
    By BrSchnitz in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 09-20-2000, 12:43 PM

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