in continuing to tinker with graphics2d, I needed to have a transparent background, but I was have trouble with getting that to work. I rewrote the graphics2d clear fuction, perhaps there is a more efficient way to do this?
but it seems to work, I can now say
mom.background(0x44009900);
and it draws a transparent background, so when I grab the PImage, it's partially transparent (alpha = 0x44 or 68 )...
again, don't know if this is helpful, just wanted to post some notes online if anyone else is trying to do the same kind of thing (rendering to a buffer, transparency, etc);
- zach
Code:
public void clear() {
// first clear what was there
g2.setComposite(AlphaComposite.getInstance(
AlphaComposite.CLEAR, 0.0f));
g2.fillRect(0, 0, width, height);
// then fill with the bg color, use the transparency bits
g2.setComposite(AlphaComposite.SrcOver);
g2.setColor(new Color(backgroundColor, true)); //http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Color.html, for alpha
g2.fillRect(0, 0, width, height);
}
(note - this is slowww, I just cannot find a way to clear the buffer and get the right kind of transparency - I don't want cumulative transparecy, I want a constant transparency). various other blend modes didn't seem to help, although I'm sure there's a way. to speed things up, I reverted back to the original call, (with a modified new color call) :
Code:
g2.setColor(new Color(backgroundColor, true));
g2.fillRect(0, 0, width, height);
but I'm still searching for something that isn't cumulative and will allow me to clear all the bits and set transparency.)