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 (Java2D) and fill
Page Index Toggle Pages: 1
PGraphics (Java2D) and fill (Read 3171 times)
PGraphics (Java2D) and fill
Feb 15th, 2007, 10:14pm
 

Hey, the contents (colors) of rectangles drawn into PGraphics are not showing up (v0124, 10.4.8). Not sure if this is the same problem that Vade was running into weeks ago (though I am using JAVA2D for drawing) or a problem with my code.

Jeremy

PGraphics context1;
 
void setup()
{
 size(300,300,JAVA2D);
 context1 = createGraphics(width-20,height-20, JAVA2D);
 context1.beginDraw();
 context1.background(0);
 context1.endDraw();
 
 //drawShape();
}
 
void draw()
{

 //background(mouseY,0,0);*/
 //stroke(0,255,0);
 //line(0,0,width,height);
 
 image(context1,0,0);
}

void mousePressed() {

  drawShape(mouseX, mouseY);
}

void drawShape(int x, int y){
 
 context1.beginDraw();
 context1.fill(255);
  // context1.noStroke();
 context1.stroke(200);
 
 context1.translate(x, y);
 context1.rect(0, 0, 40, 40);
 
 context1.endDraw();
 
}


Re: PGraphics (Java2D) and fill
Reply #1 - Feb 23rd, 2007, 12:35pm
 
i have same issue, i've discovered it yesterday and spent some time on it...

PGraphics pg;

void setup() {
 size(320,200);
 pg = createGraphics(320, 200, P3D);
 background(255);
 pg.beginDraw();
 pg.background(255);
 pg.stroke(255, 200, 0, 100);
 pg.fill(255, 200, 0, 100);
 pg.ellipse(40,40, 50, 50);
 pg.ellipse(60,60, 50, 50);
 pg.endDraw();
 image(pg, 0, 0);    
}

fill() doesn't work

i am using version 0118 Beta, and P3D becase there is null pointer exception when calling   image(pg, 0, 0);     with JAVA2D...
Re: PGraphics (Java2D) and fill
Reply #2 - Mar 3rd, 2007, 8:08am
 
This might be related to a bug I found and reported :

http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Syntax;action=display;num=1168241817
Re: PGraphics (Java2D) and fill
Reply #3 - Mar 7th, 2007, 7:43am
 
similar problem here (using 124):

PGraphics context1;
int xx = 0;
void setup()
{
 size(300,300);
 context1 = createGraphics(width-20,height-20, JAVA2D);
}

void draw()
{
 xx++;
 stroke(0,255,0);
 line(0,0,width,height);
 context1.beginDraw();
 context1.background(0,200,0);
 context1.fill(0,0,255);
 context1.stroke(200,0,0);
 context1.translate(60, xx);
 context1.rect(0, 0, 40, 40);
 context1.endDraw();
 image(context1,0,0);
}

Notice that the rect gets drawn, but it does not update. Reallocating the PGraphics object in the main loop makes the rect move down, but that seems like a waste.

c.
Re: PGraphics (Java2D) and fill
Reply #4 - Mar 7th, 2007, 3:28pm
 
for the time being, use
context1.modified = true;
after you've made any changes. but it's something that needs to be fixed--it should be getting called automatically in endDraw().
Re: PGraphics (Java2D) and fill
Reply #5 - Mar 7th, 2007, 10:33pm
 
Thanks Ben, that makes it work. Good thing that field is public.

c.
Re: PGraphics (Java2D) and fill
Reply #6 - Mar 9th, 2007, 5:29pm
 
yep, that's why she's public.
Re: PGraphics (Java2D) and fill
Reply #7 - Jun 4th, 2007, 6:32pm
 
so i'm not sure if i'm doing this correctly, but fill is still not working. My code looks like this(using 0124):

PGraphics pg;

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

void draw(){

 pg.beginDraw();
 pg.fill(0);
 pg.ellipse(mouseX, mouseY, 50,50);
 pg.modified = true;
 pg.endDraw();

 image(pg,0,0);
}
Re: PGraphics (Java2D) and fill
Reply #8 - Jun 5th, 2007, 4:35am
 
Hi,

as described in the topic's subject, the hint given by Fry is for Java2d. Wink

Quote:
PGraphics pg;

void setup() {
 size(300,300);
 pg = createGraphics(300, 300, JAVA2D);
}

void draw(){
 pg.background(255);
 pg.beginDraw();
 pg.fill(120,0,0);
 pg.ellipse(mouseX, mouseY, 50,50);
 pg.modified = true;
 pg.endDraw();
 image(pg,0,0);
}
Re: PGraphics (Java2D) and fill
Reply #9 - Jun 5th, 2007, 4:56am
 
so no fix for p3d then
Re: PGraphics (Java2D) and fill
Reply #10 - Jun 6th, 2007, 3:21pm
 
separate issue with P3D.. you need to call loadPixels() on your JAVA2D drawing surface before drawing it with P3D. (at least for now, will straighten all this out together...)
Re: PGraphics (Java2D) and fill
Reply #11 - Jun 15th, 2007, 4:59pm
 
Uhhm, with the chance of sounding like a total nitwit but where do you call the loadPixels???

PGraphics pg;  
 
void setup() {  
 size(300,300);
 pg = createGraphics(300, 300, P3D);
}  
 
void draw(){  
 background(128);
 
 pg.beginDraw();  
 pg.background(255);
 pg.fill(120,0,0);  
 pg.ellipse(mouseX, mouseY, 50,50);  
 pg.modified = true;  
 pg.endDraw();
 
 image(pg,0,0);  
}
Page Index Toggle Pages: 1