tags:

views:

305

answers:

3
+4  A: 

The canonical example for drawing antialiased lines quickly and efficiently is Xiaolin Wu's algorithm. You may want to look at that for a solid approach. Here's some sample code, too. The result of applying Wu's algorithm is on the right:

alt text

John Feminella
+1  A: 

Just curious why aren't you using a library to do this for you? For example on windows GDI+ supports antialiasing, and I'm sure that there is probably an implementation for QT & WX. Aside from those options, OpenGL would do the trick too.

GDI+ docs on anti-aliasing http://msdn.microsoft.com/en-us/library/ms535723%28VS.85%29.aspx

If you are doing it for the heck of it or academic, then just ignore me..

Zac
A: 

I was once given the task of drawing all sorts of complex and overlapping shapes that needed anti-aliasing. My solution was to draw everything to memory at a higher resolution (2x? 3x?) than the image that needed to be displayed. Then as a last step convert the high res image to low res by averaging the R,G and B separately for each of the multiple pixels in the high res version that would be reduced to a single pixel in the display image.

It may not be the most efficient way of doing things, but its dead easy to code and the visual effect was excellent.

Mick
That's basically a naive implementation of 2xFSAA, which is valid albeit there being better alternatives. Notice that Wu's algorithm has better precision than that.
Jasper Bekkers