Click to See Complete Forum and Search --> : Anti-Aliasing
Mad Compie
Jan 30th, 2001, 12:32 PM
Hi kids!
Anybody knows the algorithms for antia-aliased drawed shapes, like lines, circles, ...?
parksie
Jan 30th, 2001, 12:34 PM
How about drawing it 4 times, moving it by a pixel in each direction, then averaging the four together?
Koralt
Jan 30th, 2001, 08:21 PM
No! Don't do that -- that's not a great idea, sorry to say. ;)
I'm sure you know Bresenham's algorithm, no? (If not, just post that you don't and I'll discuss this in more depth!)
Basically, you can just use Bresenham's algorithm, and the error variable divided by the larger of the two distances (be it X distance or Y distance) is your percent alpha. So, for the current pixel, you'd use cur_error / max_error for the alpha, and you would also plot the pixel at the current location plus the step (that is, if X is greater you'd move along the Y) with an alpha of 1 - cur_error / max_error .
I hope that made some sense ...
parksie
Jan 31st, 2001, 07:05 AM
Originally posted by Koralt
No! Don't do that -- that's not a great idea, sorry to say. ;)
I didn't think so either...but in the absence of anything else... ;)
So what is Bresenham's algorithm?
Mad Compie
Jan 31st, 2001, 12:46 PM
I know about my friend Bresenham's algorithms for drawing lines and circles, but, how can I use them for my anti-aliasing algorithm?
HarryW
Jan 31st, 2001, 03:23 PM
For information on Antialiasing take a look here (http://www.gamedev.net/reference/articles/article382.asp).
For information about the Bresenham algorithm in general and subjects relevant to it take a look here (http://www.sparkseek.com/cgi-bin/search.fcgi?ac=ikt5993&ot=1001&qry=bresenham).
Sastraxi
Jan 31st, 2001, 06:44 PM
Draw it temporary at 2x resolution, then (since 4 pixels in this is one) average out the 4 pixels and plot that pixel on the normal picture. Get it?
I will post a .zip here of what I mean very soon.
Mad Compie
Feb 1st, 2001, 02:08 PM
I don't get it Sastraxi, and HarryW, I searched the Web with "Wu line", and here's the result:
http://www.sanctuary.org/~ashe/coding/aaline.html
I'll take a better look at this code...
Anyway, I put a .GIF in this thread to show the difference between antialiased and normal lines, using different background colours. If you enlarge the picture you'll see that the shaded line colours differ when using another background colour...
HarryW
Feb 1st, 2001, 02:33 PM
Do you know C code? That's fairly straightforward C code, although the way it works is probably not easy to see if you don't know what it's doing.
Did you check the articles on antialiasing on gamedev.net at the link I posted? Do you understand the Bresenham algorithm?
Part of the way the Bresenham algorithm works involves keeping note of how much of a pixel a line overlaps. With antialiasing you are shading a pixel a certain colour between the colour of the line and the colour of the background depending on how much of the pixel the line overlaps. So the same error-variable can be used. In the link you posted he says he's done it slightly differently, but the concept is the same.
What's the problem? That code is based on a linear array of rows, rather than a two dimensional array of pixels as you might expect, so you might find it a bit alien at first if you're not used to dealing with video memory in this way. It's done this way for speed purposes (antialiasing eats a lot of processor cycles).
Mad Compie
Feb 1st, 2001, 02:43 PM
The code you're talking about, is it the of your link or mine? Because I can't find the source code of the link you gave me.
Otherwise, my link uses Bresenham's algorithm to draw a line using grayed pixels as the offsets. So, in fact, this was not really the code I searched for.
But I understand you, HarryW.
I already used Bresenham's line algorithm to determine if the user clicked on a drawn line, by simply searching the line X and Y in a DB, drawing it virtually to obtain the calculated pixel positions and then comparing it with the X and Y of the user's click position. It's really fast!
HarryW
Feb 1st, 2001, 04:45 PM
I was referring to the code at the link you posted. So err.... what don't you get?
HarryW
Feb 2nd, 2001, 01:32 PM
To be honest I'm not sure what those functions are supposed to do. All the algorithm should be doing is altering the intensity of colour of pixels around the line. You can do the same sort of thing with coloured graphics, just changing the bias between one colour or the other. I hope that makes some sense, I don't know how to express it properly.
Mad Compie
Feb 2nd, 2001, 01:34 PM
OK I got the picture. I'll start converting it to VB...
Thanks for replying.
Mad Compie
Feb 2nd, 2001, 02:07 PM
Oops, a last tribute to this thread: I found some very interesting links at:
http://www.efg2.com/lab/library/Graphics.htm
This site contains really good examples and algorithms!
Bye again.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.