Results 1 to 14 of 14

Thread: Anti-Aliasing

  1. #1

    Thread Starter
    Fanatic Member Mad Compie's Avatar
    Join Date
    Aug 2000
    Location
    Kuurne (Belgium)
    Posts
    553

    Unhappy

    Hi kids!

    Anybody knows the algorithms for antia-aliased drawed shapes, like lines, circles, ...?

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  3. #3
    Member
    Join Date
    Aug 2000
    Location
    USA
    Posts
    32

    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 ...
    -Koralt

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169

    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

  5. #5

    Thread Starter
    Fanatic Member Mad Compie's Avatar
    Join Date
    Aug 2000
    Location
    Kuurne (Belgium)
    Posts
    553
    I know about my friend Bresenham's algorithms for drawing lines and circles, but, how can I use them for my anti-aliasing algorithm?

  6. #6
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    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."

  7. #7
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    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)

  8. #8

    Thread Starter
    Fanatic Member Mad Compie's Avatar
    Join Date
    Aug 2000
    Location
    Kuurne (Belgium)
    Posts
    553
    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...

  9. #9
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    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."

  10. #10

    Thread Starter
    Fanatic Member Mad Compie's Avatar
    Join Date
    Aug 2000
    Location
    Kuurne (Belgium)
    Posts
    553
    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!

  11. #11
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    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."

  12. #12
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    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."

  13. #13

    Thread Starter
    Fanatic Member Mad Compie's Avatar
    Join Date
    Aug 2000
    Location
    Kuurne (Belgium)
    Posts
    553
    OK I got the picture. I'll start converting it to VB...
    Thanks for replying.

  14. #14

    Thread Starter
    Fanatic Member Mad Compie's Avatar
    Join Date
    Aug 2000
    Location
    Kuurne (Belgium)
    Posts
    553
    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
  •  



Click Here to Expand Forum to Full Width