views:

115

answers:

2

I am writing a paint program in Delphi. The user clicks 2 points on the screen and a line is drawn between them. I want the lines to be anti-aliased. I put this code in create() procedure of the OpenGL class (which is called just 1 time in the start):

 glEnable(GL_LINE_SMOOTH);
 glEnable(GL_BLEND);
 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);

When I start drawing, the first, second and maybe the third lines are drawn fine. But interestingly enough, when the number of the lines increases (say 7, 8 lines), the anti-aliasing starts to fail! By adding each line on the screen, it just gets worse and the lines edges starts to become like sawtooth!!

I also put the same code on the top of my draw() procedure which draws the lines (and runs by each click of the mouse), but nothing changes.

Am I doing something wrong here? Anybody has any suggestion?

+2  A: 

Check the value of GL_SMOOTH_LINE_WIDTH_RANGE and compare it against the glLineWidth()s you're trying to use.

genpfault
Good answer--I had assumed they were all the same width, but he didn't say that explicitly.
Drew Hall
Upon further re-reading I'm not sure where I got the idea either :(
genpfault
Are you sure standard OpenGL has GL_SMOOTH_LINE_WIDTH_RANGE as a constant? Because it doesn't recognize it in Delphi (using standard OpenGL.dll).BTW, I am using 3 in the glLineWidth() and I even checked with 1 and get the same problem.
Flom Enol
I added the screenshots in the comment above.
Flom Enol
+2  A: 

Are You sure You're not drawing any line segment more than once? Do You call glClear before doing any drawing?

Rekin
Thanks for your great answer! It was exactly the problem. I was drawing each line more than once and that caused the effect.
Flom Enol