Transparency and CAIRO_OPERATOR_SOURCE

mike e <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <HK2PR0401MB13786FC319061216D66C22F9B0E60@HK2PR0401MB1378.apcprd04.prod.outlook.com>
Hi,


I'm currently writing a program that uses cairo (cairo-xlib precisely), and I seem to be having a problem with the cairo source operator.


My program redraws itself many times per second, which means (I believe) that I have two options regarding transparency: clear the surface before each redraw, or use CAIRO_OPERATOR_SOURCE for each draw (please correct me if I'm wrong).


I'm trying to draw some rounded rectangles against a surface, which seems to involve some transparency (anti-aliasing I'm sure).  My problem is that each subsequent redraw of the rounded rectangle causes the edges to become more defined, until they're eventually just 45 degree lines.  I would expect this behavior from CAIRO_OPERATOR_OVER, but not CAIRO_OPERATOR_SOURCE; is there something I'm missing?


Is it possible that there is some kind of overlapping going on, even with CAIRO_OPERATOR_SOURCE?


It is necessary that I redraw the rounded rectangle often.


Here's what I'm using for a rounded rectangle (taken mostly from http://cairographics.org/samples/rounded_rectangle/):

void rounded_rectangle(cairo_t *context,
                       double x, double y,
                       double width, double height,
                       double corner_radius)
{
    const double aspect = 1.0;

    double radius = corner_radius / aspect;
    double degrees = M_PI / 180.0;

    cairo_new_sub_path(context);
    cairo_arc(context, x + width - radius, y + radius, radius, -90 * degrees, 0 * degrees);
    cairo_arc(context, x + width - radius, y + height - radius, radius, 0 * degrees, 90 * degrees);
    cairo_arc(context, x + radius, y + height - radius, radius, 90 * degrees, 180 * degrees);
    cairo_arc(context, x + radius, y + radius, radius, 180 * degrees, 270 * degrees);
    cairo_close_path(context);
}

Here's how I'm redrawing:
for (running = 1; running == 1;)
{
            ...
      cairo_set_operator(ctx, CAIRO_OPERATOR_SOURCE);
      cairo_set_source_rgba(ctx, c.red, c.green, c.blue, c.alpha);
      rounded_rectangle(context, x, y, w, h, opt.rounding);
      cairo_fill_preserve(context);
      ...
}

Sorry if the formatting is poor, and thanks for any help!

Regards,
Mike

-- 
cairo mailing list
[email protected]
https://lists.cairographics.org/mailman/listinfo/cairo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.