Avoiding seams (was: [cairo] Best strategy for complex screen drawing)
timothee.lecomte at ens.fr
Mon Nov 28 14:29:38 PST 2005
Hi all !
I would like to sum up the situation about my speed issues using cairo.
Alexander Larsson explained that it was a bad idea to use fill and
stroke to avoid seams between polygons, but suggested to use an
intermediate surface drawn with CAIRO_OPERATOR_ADD.
Here are peaces of my code :
Somewhere before actual drawing, I create the intermediate drawing surface :
cairo_surface_t *polygon_surface = cairo_surface_create_similar(
polygon_cr = cairo_create (polygon_surface);
cairo_set_operator (polygon_cr, CAIRO_OPERATOR_ADD); /* or SATURATE,
or OVER for testing purpose */
Later, I draw polygons with :
cr = polygon_cr;
cairo_move_to(cr, device_x(corners.x), device_y(corners.y));
for (int i=1;i<n;i++)
cairo_line_to(cr, device_x(corners[i].x), device_y(corners[i].y));
wxt_cairo_fill(fillstyle, fillpar ); /* set a plain color via
cr = main_cr;
And finally, I copy my polygon surface to the main cairo context :
cairo_set_source_surface (cr, polygon_surface, 0, 0);
Let's talk about results :
* desired output (obtained with cairo_fill_preserve and cairo_stroke ):
No seams between polygons, but really slow as expected.
* with CAIRO_OPERATOR_OVER :
As expected, seams between polygons.
* with CAIRO_OPERATOR_ADD :
No seam, but problems of 'transparency' induced by the ADD operation
* with CAIRO_OPERATOR_SATURATE :
No seam, but first-drawn polygons hide last ones, so to get the
desired output, it would imply to render front-to-back and it would add
a lot of complexity to my code...
Can someone help me to sort all these things and get both speed and
Thanks for your consideration and time.
More information about the cairo