[cairo] Transparency
Carl Worth
cworth at cworth.org
Sat Jul 14 10:53:24 PDT 2007
Hi Jose,
I'm glad you're trying out cairo, and I'm glad you came here when you
ran into some problems. Hopefully we can help you get things working
the way you want.
On Sat, 14 Jul 2007 12:10:04 +0200, "Jose Hevia" wrote:
> I just want to confirm if those are bugs:
> I want to clear a surface with cairo,so the screen displays a color
> background with transparency, so I do:
>
> cairo_set_source_rgba (new->cr, 0,1,1,0.1);
So far, so good. You've now set the source pattern to a uniform color,
(cyan at 10% opacity).
> cairo_set_source_surface (new->cr,new->surface, 0, 0);
Oops, now you just replaced the source pattern with a new source
pattern based on the contents of new->surface. So if new->surface is
the same surface that new->cr is targeting, you won't be able to get
many drawing operations to have any useful effect, (you'll be drawing
the same content on top of itself).
> cairo_set_operator (new->cr, CAIRO_OPERATOR_CLEAR);
Oops, again, now you just started using an operator that completely
ignores the source pattern. This operator sets the destination to 0 in
every channel. What you want instead is the SOURCE operator that
copies the source pattern to the destination, (entirely ignoring the
original destination contents---unlike the default OVER operator which
blends the source pattern over the destination).
> cairo_paint(new->cr);
And this part is correct.
So the complete and corrected sequence is:
/* Clear contents to cyan with 10% opacity */
cairo_set_source_rgba (new->cr, 0., 1., 1., 0.1);
cairo_set_operator (new->cr, CAIRO_OPERATOR_SOURCE);
cairo_paint (new->cr);
> BUG: I can't change clearing color. Is always(0,0,0,0). Is this a
> bug?
No bug. Cairo was just implementing CAIRO_OPERATOR_CLEAR that you
asked for.
You might take a look here, which directly answers your original
question:
http://cairographics.org/FAQ/#clear_a_surface
As well as here which explains some of the general concepts such as
source patterns:
http://cairographics.org/tutorial/
> ANOTHER BUG:Transparency seems a function of the screen luminosity
> ((R+G+B)/3), instead of alpha--->(255,255.255,0) is always opaque
> white, no matter what is behind the window.
>
> Black (0,0,0,255) is opaque through.
I don't understand your question here. Cairo definitely doesn't do any
luminosity calculations. Is it inter-window transparency that you're
having trouble getting to work? If so, you'll have to ensure that
you're using an ARGB Window visual so that it contain the alpha
values.
Also, you'll need to ensure that there's a compositing manager doing
something useful with those alpha values. But as you say:
> System Info: Ubuntu FF with beryl, cairo 1.4.2
Beryl should be doing the compositing manager role just fine.
So hopefully that helps. Please let us know if you have any further
questions. And have fun with cairo!
-Carl
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.cairographics.org/archives/cairo/attachments/20070714/be8aa1a6/attachment.pgp
More information about the cairo
mailing list