Lines one pixel too short


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.

      glColor3ub(255, 255, 255);

      glColor3ub(255, 0, 0);

renders to
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 :slight_smile:

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.

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.

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?

Why ? because it is correct.

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

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.