We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › background(), alpha and PGraphics
Page Index Toggle Pages: 1
background(), alpha and PGraphics (Read 878 times)
background(), alpha and PGraphics
May 4th, 2010, 7:38pm
 
Hey there,

I guess this topic has already been discussed, but I couldnt find any matching topic.


Could it be that it's not possible to use >1bit alpha in PGraphics objects?

here is an example to demonstrate my problem:

Code:

PGraphics bg;
PGraphics element;

void setup() {
 size(400, 400);
 
 bg = createGraphics(width, height, JAVA2D);
 element = createGraphics(width, height, JAVA2D);
}

void draw() {
 background(0);

 bg.beginDraw();
 bg.smooth();
 bg.background(0, 20);
 bg.stroke(255);
 bg.line(0, 0, mouseX, mouseY);
 bg.endDraw();
 
 element.beginDraw();
 element.smooth();
 element.background(0, 0);
 element.fill(255);
 element.ellipse(random(width), height / 2, 20, 20);
 element.endDraw();
 
 image(bg, 0, 0);
 image(element, 0, 0);
}


this doesnt apply any fading to background, instead the whole frame is redrawn, but from my understanding the logic is as following:

* clear the frame
* apply a fading to background
* draw on background
* clear elements
* redraw elements
* draw both graphics on the empty frame


Id like to achieve the effect, that the background graphic is fading, whereas the elements are redrawn, but it doesnt seem possible this way. I thought PGraphics were sort of a graphics buffer? Could someone point me in the right direction?


thanks in advance! Smiley
-daniel
Re: background(), alpha and PGraphics
Reply #1 - May 5th, 2010, 4:53am
 
Background replaces completely (overwrites) the pixels of the graphics.
Try instead:
 bg.fill(0, 20);
 bg.rect(0, 0, width, height);
Re: background(), alpha and PGraphics
Reply #2 - May 5th, 2010, 7:58am
 
cool, that works better! Still doesnt let the lines vanish completely, I still see them a bit with an opacity of about 10% or so!

Anyway: this helped me alot, thank you!
Page Index Toggle Pages: 1