I want to draw transparent windows (with alpha channel) on Linux (GTK) and OSX. Is there an API to do that ? Note that I don't want to set a global transparency, the alpha level should be set per pixel.
I'm looking for the same kind of API than the UpdateLayeredWindow function on Windows, as in this example: Per Pixel Alpha Blend.
For Mac OS X, see the RoundTransparentWindow sample code. It works by using a custom completely transparent window and drawing shapes in it. Although the example only uses shapes with hard edges + overall alpha, arbitrary alpha can be used.
Although the example uses a custom window, you can use the same technique to punch holes in normal windows by calling
setOpaque:NO
. Hacky example:The primary limitation of this technique is that the standard drop shadow doesn’t interact very well with alpha-blended edges.
I found this code in my experiments folder from earlier this year. I can't remember how much of this I wrote and how much is based on examples from elsewhere in the Internet.
This example will display a partially-transparent blue window with a fully opaque GTK+ button in the centre. Drawing, for example, an alpha-blended PNG somewhere inside the window should result in it being composited correctly. Hopefully this will put you on the right track.
Compile it with the following:
Now for the code: