antialias on arc

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

  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…

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

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

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

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

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.