View Full Version : GL_LINE_SMOOTH produces "bold" lines (big width)

12-30-2011, 08:04 AM

All is in the subject : only enabling or disabling GL_LINE_SMOOTH gives thick or thin lines.
I join an image.
What is the cause that thick lines ? How to disable that ?

I enabled GL_LINE_SMOOTH to do antialiasing on lines...

Thanks for your help.

12-30-2011, 09:56 AM
What is the cause that thick lines ?

To remove aliasing, the line gets dilated by partially affecting neighboring pixels' values (lying adjacent to pixels belonging to line) to give smooth appearance hence the thickness.

12-30-2011, 10:18 AM
Thanks for your answer.

Yes but there is a so big difference between thin and thick lines...
The 3D view looks like a cartoon with big edges.
In 2D when I zoom out I have "bold" black areas where there a many lines (details).
Enabling the blending does not change anything.
For me it seems unusable like this...

Do you confirm that it is the correct behavior ?

12-30-2011, 10:56 AM
From hardware point of view. It also depends on the card that you use. What card are you using?

Enabling the blending does not change anything.
What king of blending functions are you using?

Try using options in glHint().

12-31-2011, 04:12 PM
What is the cause that thick lines ?Your line coordinates are most likely bad (between pixels instead of at center of pixels). However, i guess something else is also going on as the partially covered pixels look full color and not a mix between line and scene colors (blending not enabled? used blend mode needs, but is missing an alpha channel? overdraw? user has overridden anti-alias in drivers?).

12-31-2011, 04:55 PM
Do you confirm that it is the correct behavior ?

I checked. Your line has a thickness of 1 pixel.
When you enable smoothing, thickness becomes 3. So it is normal.

Perhaps you shouldn't use a old feature like smoothing. I recommend using FSAA instead.

01-02-2012, 01:48 AM
Thanks for your answers.

Yes the blending is disable on my screenshot. It does not change the rendering "quality" : the lines look thick.
And I think I used the classical code :

glEnable (GL_BLEND);

glEnable (GL_LINE_SMOOTH);

I saw when searching on the net that there is a FSAA method.
Will this method generate more thin lines or will I only have better performances ?


01-02-2012, 07:36 AM
With FSAA, the lines would look fine. Different vendors implement FSAA differently and of course, different GPU generation support different AA-levels : some support 2x and 4x and some support 2x, 6x, 4x, 8x and some support 2x, 4x, 8x and Quincunx ( http://www.tomshardware.com/reviews/anti-aliasing-nvidia-geforce-amd-radeon,2868-5.html ) and some support up to 16x)

Try them and see which one you like. You can just go into control panel and enable it. IMO, 6x and above yields good results. If you like it, then you can create a FSAA context programmatically.

01-03-2012, 03:09 AM
As pointed out above, use alpha blending for GL_LINE_SMOOTH. Call glLineWidth to tweak the thickness when wider than 1px (with alpha=1.0). To draw lines that appear thinner than 1px, scale the alpha, e.g. glColor(1,1,1,0.5) for 0.5px wide lines. glLineWidth does not accept values smaller than 1.0 (=1px width).

Tip: use glLineWidth(~1.3) for consistent anti-aliasing. Perfectly vertical or horizontal lines with glLineWidth(1) wide may seem thinner than diagonal lines. Likewise, if you still prefer to keep perfectly vertical/horizontal 1px wide, you can scale the alpha of diagonal lines.

GL_LINE_SMOOTH generally gives nicer anti-aliased lines than FSAA/MSAA, unless you got 16x and up. It may be more efficient memory wise (smaller framebuffer footprint). But be aware that GL_LINE_SMOOTH quality/rasterization may (subtly) vary between vendors.

Also take note that some Intel hardware has absolutely p!ss-poor line rendering qualiy. I've seen some on-board chipsets drivers fail to even rasterize regular aliased 1px wide lines properly on diagonals, similar to your screenshot, but with inexplicably alternating thickness and occasionally jittering pixels.

01-03-2012, 08:55 AM

So FSAA is a solution for me.

Remdul, I tested again after your post but no : I can not obtain good results. And blending works but gives artifacts in some cases (in 3D view). If you say that it may work then there are errors in our code but I can not find where...

I tested FSAA like V-man suggested : that gives good results in 2D and 3D.
So I did a test in my code using a Nehe tutorial (http://nehe.gamedev.net/tutorial/fullscreen_antialiasing/16008/).
I join the result. It is ok for me and I have no more artifacts in 3D. :)

Many thanks for your help !