PDA

View Full Version : antialias on arc



10-04-2006, 11:30 AM
Hi all,
I'm quite new to OpenGl and I'd like to use it to render a rounded rectangle, basically a rectangle with rounded corners. Is there a way to have antialising while drawing an arc?
thanks for any help
Bye

remdul
10-04-2006, 02:14 PM
1) Use an alpha blended texture (either for the entire rectangle or only the corners).

Or generate some extra triangles to get those round edges. First compute the vertex positions for the edge and...

2) use glPolygonSmooth to render antialiased triangles. This may be slow, and you need to sort the triangles.

3) render the rectangle interior normally, then draw an anti-aliased line (glLineSmooth) along the border on top of that. Set glLineWidth to 2. Disable depth_test or use glPolygonOffset to push the interior back to avoid z-fighting.

4) use FSAA, but this is a bit of overkill and slower.

5) ...

I'd suggest #3, it is fast and easy to set up, plus you can give the border a different color.

k_szczech
10-05-2006, 12:46 AM
Another suggestion:
When rendering your quad draw just one GL_POLYGON or GL_TRIANGLE_FAN primitive - draw all pixels of the rounded rectangle, but decrease it's size by half of pixel.
Now enable blending - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA).
Draw GL_TRIANGLE_STRIP or GL_QUAD_STRIP around your rounded rectangle - inner edge of this strip should draw a rounded rectangle smaller by half a pixel to match exactly the one you just drawn - use color (r,g,b,1.0). Outer edge should draw rounded rectangle larger by half a pixel and have color (r,g,b,0.0).
So that triangle strip should have width of exactly 1 pixel.
If you play it right you should get nearly perfect antialiasing, but this approach has one drawback - you need to sort your polygons before drawing since depth testing will not work properly on edges.