Chris Randall
Chris Randall

Reputation: 111

Why is GL_LINES blurry?

Consider the following code:

glColor4ub(255, 255, 255,255);

glBegin(GL_QUADS);
glVertex2i(100, 100);
glVertex2i(300, 100);
glVertex2i(300, 101);
glVertex2i(100, 101);
glEnd();

glLineWidth(1);

glBegin(GL_LINES);
glVertex2i(100,200);
glVertex2i(300,200);
glEnd();

That results in the following, which I don't understand:

GL_LINES v GL_QUADS

I have not enabled (and actually have gone so far as to disable) GL_LINE_SMOOTH and GL_SMOOTH. If this is a global anti-aliasing "feature," shouldn't it affect GL_QUADS as well?

Halp?

Upvotes: 3

Views: 594

Answers (2)

Ben Voigt
Ben Voigt

Reputation: 283634

It is because you passed a coordinate which is halfway between two pixels.

For quads, borders between pixels are good and give you nice clean edges.

For lines, vertices between pixels causes half the line to fall on each. For example, if you were using glLineWidth(2), then this would work very well (half the line is exactly one pixel, so there's exactly one pixel to either side). For glLineWidth(1), you're getting only half a pixel to either side.

Upvotes: 5

FogleBird
FogleBird

Reputation: 76772

What if you do this?

glBegin(GL_LINES);
glVertex2f(100, 200.5f);
glVertex2f(300, 200.5f);
glEnd();

Upvotes: 1

Related Questions