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 & HelpSyntax Questions › PGraphics, so simple, but....
Page Index Toggle Pages: 1
PGraphics, so simple, but.... (Read 1189 times)
PGraphics, so simple, but....
Sep 25th, 2009, 7:20pm
 
Hi,
New to this.  PGraphic overlays render as overlays, but I can't seem to get the PGraphic's background to drop out without leaving trails. I think I'm missing something real basic here. I'd like to avoid defining a background color for the overlay.

Thanks,  -worker

Code:
PGraphics pg;

void setup() {
 size(200, 200);
 background(120, 0, 0);
 pg = createGraphics(150, 150, P3D);
}

void draw() {
 pg.beginDraw();
 
 //pg.background(120, 0, 0);  
 // this gives me
 // what I want, but its kind of a hack and it
 // doesn't really solve this problem


 pg.stroke(255);
 pg.strokeWeight(4);
 pg.line(40, 40, mouseX, mouseY);
 pg.endDraw();
 
 image(pg, 10, 10);
 
}
Re: PGraphics, so simple, but....
Reply #1 - Sep 25th, 2009, 8:11pm
 
I dont understand.
you get the trails because you dont draw a background.
If you draw one you get what you want.
thats the normal behavior. i wouldnt call it a hack. thats the way it is.
whats the problem with calling background? what do you want to achieve?
Re: PGraphics, so simple, but....
Reply #2 - Sep 25th, 2009, 9:32pm
 
Is it what you are trying to do ?

Quote:
PGraphics pg;

void setup() {
  size(200, 200,P3D);
  pg = createGraphics(200, 200, P3D);
}

void draw() {
  pg.beginDraw();
  pg.fill(0, 20);
  pg.rect(0,0,200,200);
  pg.stroke(255);
  pg.strokeWeight(4);
  pg.line(100, 100, mouseX, mouseY);
  pg.endDraw();
  
  image(pg, 0, 0);
  


Re: PGraphics, so simple, but....
Reply #3 - Sep 26th, 2009, 12:31am
 
Thanks for the responses.

What I am trying to do is overlay a smaller PGraphics layer within the base sketch layer. I want the background of this PGraphics layer to keep its alpha so that the the base layer is visible behind it, without having the trails left behind by the PGraphic layer. I guess what I am seeking is a way to redraw and update the overlayed PGraphics layer before it is drawn onto the screen.

My plan is to have several off-screen PGraphics buffers that will be composited over each other. I'm starting to think that this approach is not the way to do this.
Re: PGraphics, so simple, but....
Reply #4 - Sep 26th, 2009, 2:53am
 
This example shows how to do some overlay with PGraphics.
Tell me if it's close to what you want to do.

Quote:
PGraphics pg;

void setup() {
  size(200, 200,P3D);
  pg = createGraphics(200, 200, P3D);
 background(255, 0, 0);
}

void draw() {
  pg.beginDraw();
  
  pg.background(255, 0, 0);
  pg.fill(0,0, 255, 127);
  pg.noStroke();
  pg.ellipse(mouseX, mouseY,30,30);
  
  pg.stroke(255,255,0,127);
  pg.strokeWeight(4);
  pg.line(100, 100, mouseX, mouseY);
  
  pg.fill(0,255, 0, 127);
  pg.noStroke();
  pg.rect(50,50,200,200);

  pg.endDraw();
  
  image(pg, 0, 0);
  


Re: PGraphics, so simple, but....
Reply #5 - Sep 26th, 2009, 4:29am
 
I think I found a solution. I noticed that adding an alpha value to  pg.background allows contol over the PGraphics opacity. I wasn't aware that RGBA values could be applied to the background.

Thanks again for helping me out.

Code:
PGraphics pg;
float x;

void setup() {
size(200, 200,P3D);
pg = createGraphics(160, 180, P3D);

}

void draw() {
background(255, 0, 255);
rect( x, 100, 20, 20);
x +=1;
if( x == width) {
x = 0;
}

pg.beginDraw();

pg.background(255, 255, 0, 128);
pg.fill(0,0, 255, 127);
pg.noStroke();
pg.ellipse(mouseX, mouseY,30,30);

pg.stroke(255,255,0,127);
pg.strokeWeight(4);
pg.line(100, 100, mouseX, mouseY);

pg.fill(0,255, 0, 127);
pg.noStroke();
pg.rect(50,50,200,200);

pg.endDraw();

image(pg, 20, 10);


}
Re: PGraphics, so simple, but....
Reply #6 - Sep 26th, 2009, 2:42pm
 
I thought you wanted to apply the overlay thing only on top of pg.background().

It does make more sense now. Smiley
Page Index Toggle Pages: 1