[cairo] Transparency and CAIRO_OPERATOR_SOURCE

mike e Toqoz at hotmail.com
Tue May 16 08:12:29 UTC 2017


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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.cairographics.org/archives/cairo/attachments/20170516/1e111b30/attachment.html>


More information about the cairo mailing list