[cairo] Transparency and CAIRO_OPERATOR_SOURCE
Toqoz at hotmail.com
Tue May 16 08:12:29 UTC 2017
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,
const double aspect = 1.0;
double radius = corner_radius / aspect;
double degrees = M_PI / 180.0;
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);
Here's how I'm redrawing:
for (running = 1; running == 1;)
cairo_set_source_rgba(ctx, c.red, c.green, c.blue, c.alpha);
rounded_rectangle(context, x, y, w, h, opt.rounding);
Sorry if the formatting is poor, and thanks for any help!
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the cairo