|
-
Jan 30th, 2001, 01:32 PM
#1
Thread Starter
Fanatic Member
Hi kids!
Anybody knows the algorithms for antia-aliased drawed shapes, like lines, circles, ...?
-
Jan 30th, 2001, 01:34 PM
#2
Monday Morning Lunatic
How about drawing it 4 times, moving it by a pixel in each direction, then averaging the four together?
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jan 30th, 2001, 09:21 PM
#3
Member
Yeek!
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 ...
-
Jan 31st, 2001, 08:05 AM
#4
Monday Morning Lunatic
Re: Yeek!
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?
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jan 31st, 2001, 01:46 PM
#5
Thread Starter
Fanatic Member
I know about my friend Bresenham's algorithms for drawing lines and circles, but, how can I use them for my anti-aliasing algorithm?
-
Jan 31st, 2001, 04:23 PM
#6
Frenzied Member
For information on Antialiasing take a look here.
For information about the Bresenham algorithm in general and subjects relevant to it take a look here.
Harry.
"From one thing, know ten thousand things."
-
Jan 31st, 2001, 07:44 PM
#7
Good Ol' Platypus
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.
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Feb 1st, 2001, 03:08 PM
#8
Thread Starter
Fanatic Member
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...
-
Feb 1st, 2001, 03:33 PM
#9
Frenzied Member
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).
Harry.
"From one thing, know ten thousand things."
-
Feb 1st, 2001, 03:43 PM
#10
Thread Starter
Fanatic Member
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!
-
Feb 1st, 2001, 05:45 PM
#11
Frenzied Member
I was referring to the code at the link you posted. So err.... what don't you get?
Harry.
"From one thing, know ten thousand things."
-
Feb 2nd, 2001, 02:32 PM
#12
Frenzied Member
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.
Harry.
"From one thing, know ten thousand things."
-
Feb 2nd, 2001, 02:34 PM
#13
Thread Starter
Fanatic Member
OK I got the picture. I'll start converting it to VB...
Thanks for replying.
-
Feb 2nd, 2001, 03:07 PM
#14
Thread Starter
Fanatic Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|