Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [DBP] anti-aliased circles and rounded boxes, at last!

Author
Message
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 17th Jun 2010 02:52 Edited at: 17th Jun 2010 02:57
Last year I posted a snippet showing how to draw anti-aliased lines using a method by Xiaolin Wu.



In "Graphics Gems 2",

http://books.google.com/books?id=ZQQssYF3i7wC&pg=PA446&lpg=PA446&dq=Fast+Anti-Aliased+Circle+Generation&source=web&ots=3tEqjTmXRM&sig=8Yalwrv81RcW5QPg46_fjgmRgZU&hl=en&sa=X&oi=book_result&resnum=2&ct=result#v=onepage&q=Fast%20Anti-Aliased%20Circle%20Generation&f=false

Wu describes how to do the same with circles. Between that article and a php implementation I found here I was able to create the code below. It's pretty identical to the php implementation, hence why I felt the need to at least document my source, but I had to make a few minor changes to the alpha pixel order.

The below code also includes several other functions I've come up with while drawing my iTunes interface as posted recently in WIP. OBese87 wrote a rounded box routine which I've adapted into my iTunes clone, but now as of last night I have an anti-aliased rounded box routine.

There's a few different versions of the same functions, the only difference being how they're drawn to screen. To use true alpha, I have only the box command to use, which does slow it down quite a bit, so at this time the alpha version isn't ideal for real-time use but maybe for drawing new images saved as sprites. It would be much quicker if I could set alpha values for the color when writing directly to the back buffer using the pDot() function.




"Any sufficiently advanced technology is indistinguishable from magic" ~ Arthur C. Clarke

Attachments

Login to view attachments
Digger412
17
Years of Service
User Offline
Joined: 12th Jun 2007
Location:
Posted: 17th Jun 2010 16:55
@Phaelax - very nice job, I had always wondered how to go about AA'ing 2d shapes in DBP but it's never been anything I've attempted. Also, looking at your code made me want to cry with joy because it's formatted so nicely and easy to read
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 17th Jun 2010 23:57
I forgot to mention, the IF statements you see in the wuRoundedBox function are to correct a few irregularities when the rounded corners meet the straight edges. Nothing major, just makes it look cleaner.

As often as I take breaks between code (sometimes many months), if I didn't format my code cleanly I'd never finish anything cause I'd forget wtf I was doing.


"Any sufficiently advanced technology is indistinguishable from magic" ~ Arthur C. Clarke
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 29th Jun 2010 23:31
Very nice, I'm using it already!!

Login to post a reply

Server time is: 2024-11-24 13:12:00
Your offset time is: 2024-11-24 13:12:00