Jump to content
  • Advertisement
Sign in to follow this  
LGAB

OpenGL Bezier shapes and anti-aliasing

This topic is 5037 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everyone, I hope I'm posting this in the right place. I've coded a 2D-interface for manipulating bezier curves, the interface is accelrated with OpenGL and the result is rendered to a buffer to be used by other parts of the application (think masks in adobe after effects), it's a non-realtime application by the way ;) I can easily draw lines in this buffer according to the bezier spline (using custom pixel- and line-drawing routines), and have made a bit of progress with filling the shape with white so it can be used as mask/alpha, but with bad aliasing. I'd like som advice on a good way of filling these shapes, and I need it to be anti-aliased! I don't need realtime here, fast is nice, but I'm happy with anything at this point. The input is floating point precision bezier curves at any resolution you desire, how do I turn this into nice antialised masks? :) Thanks

Share this post


Link to post
Share on other sites
Advertisement
First off I'd think that you'll only need to deal with aliasing issues at the edge of the filled shape - the interior of the shape can be scanline-converted and filled in the regular way, because it's all going to be fully filled. It's just the pixels at the boundaries that'll need messing with.

So I guess it'd mean modifications to your pixel and line drawing routines. What techniques are you currently using?

Share this post


Link to post
Share on other sites
You could simply render the thing at 4X the resolution (or more) then box filter down the image. That would probably be the most straightforward way to do it.

Hope that helps,


Josh

Share this post


Link to post
Share on other sites
Hey (sorry for the delay), I'm currently using some pretty fast line-code I found, it draws "hard" lines in my buffer, then I go over the buffer checking for non-black pixels, storing their values, then draw lines between them to fill the shape for each line of the image. Still got some bugs in this routine tho.

I realize I just need to operate on the out-line pixels, the way I figure it, I should be able to take some sort of average for each pixel based on how close each coordinate of the curve comes to the center of a pixels "area". Or calculate the distance to the line for the surrounding pixels. Anyway, what I really need is an anti-alised line function, I suppose, and hope fully I can combine that with my fill-routine (which isn't exactly fast as it is..).

Doubling the image and resampling it seems to slow for me, as I'm going to need an acceptable level of interaction, just like with rendering 3D images, there's an infinite amount of data you have access to so I'm sure there's a slick way of anti-aliasing this thing :)

Share this post


Link to post
Share on other sites
I'd recommend getting your hands on a copy of Foley et. al. if you don't already have one. It covers this sort of thing extensively - both fast rasterization of 2D primitives, and things like antialiasing.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by LGAB
Doubling the image and resampling it seems to slow for me


I don't think doubling the size of the image would double the time needed to render your curve. That's the first thing I'd try actually... at least to see if it works. It shouln't be too hard (nor long) to do since your code seems to work fine.

Share this post


Link to post
Share on other sites
For optimal AA you would have to calculate for each pixel what fraction of the pixel is part of the bezier shape. I don't know if this is possible or how expensive this is.

Easy AA is rendering the border (not the whole shape) at a higher resolution and averaging those subpixels.

Share this post


Link to post
Share on other sites
If he's using something like the midpoint technique to generate his lines, it shouldn't be too hard to calculate what fraction of the fragment should be written to each side of the line. Of course given that these are filled primitives he'd probably want to write the interior pixel as full colour regardless of the covered fraction.

Share this post


Link to post
Share on other sites
Hey again (sorry for the late reply again)

superpig; I'm buying that book for sure!

Thanks for your suggestions, I'll keep trying

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!