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 and rect(), it only draw once
Page Index Toggle Pages: 1
PGraphics and rect(), it only draw once (Read 653 times)
PGraphics and rect(), it only draw once
Dec 5th, 2008, 4:51pm
 
hi,

i have a problem with the rect() method on a PGraphics window, only with rect, when i run the sketch it draw that once. The other primitive like line or ellipse are working properly.

is it a bug?

Re: PGraphics and rect(), it only draw once
Reply #1 - Dec 5th, 2008, 6:45pm
 
Yes. In your code... Which we can't guess...
If it is too long, try reproducing your issue in a simpler sketch. Sometime, doing that, the problem just shows itself!
Re: PGraphics and rect(), it only draw once
Reply #2 - Dec 5th, 2008, 7:33pm
 
http://pastie.org/332063

the draw method just call generateFrame()

i really cannot see anything wrong.
Re: PGraphics and rect(), it only draw once
Reply #3 - Dec 5th, 2008, 10:48pm
 
Neither me.
Even by supplying the missing code (shown below), I see little graphics, and I have no idea of what is wrong for you.
Code:
int OUTPUT_WINDOW_POSITION_X = 50, OUTPUT_WINDOW_POSITION_Y = 50;

Text1 t;
PGraphics outputScreen;
int sliderValue1 = 21;

void setup()
{
size(500, 500);
t = new Text1();
outputScreen = createGraphics(200, 200, P2D);
}

void draw()
{
background(250);
t.generateFrame();
}
Re: PGraphics and rect(), it only draw once
Reply #4 - Dec 5th, 2008, 11:50pm
 
my Pgraphics is a P3D window, that could affect something?
Re: PGraphics and rect(), it only draw once
Reply #5 - Dec 6th, 2008, 12:34am
 
Ah, "once"! It is supposed to draw several rects? Then perhaps you should put some code in the move() routine, currently you draw all rects at the same place.
Re: PGraphics and rect(), it only draw once
Reply #6 - Dec 6th, 2008, 10:59am
 
i don't understand what you mean. i'm trying to draw the same rect in the same position.
Re: PGraphics and rect(), it only draw once
Reply #7 - Dec 6th, 2008, 11:25am
 
In this case, it works perfectly for me. I see a small black square and a little diagonal line beside it.
Re: PGraphics and rect(), it only draw once
Reply #8 - Dec 6th, 2008, 1:13pm
 
I'm quite sure that's a bug, i also have the same problem with text.

Apparently rect and text don't work with PGraphics of small size.

i tried this script, it does the same for both window but it only draw on the second(bigger) one, even if i invert the sizes it only draw the big one.

http://pastie.org/332578

Re: PGraphics and rect(), it only draw once
Reply #9 - Dec 6th, 2008, 3:13pm
 
Classical error, you forgot that draw(), as well as beginDraw(), doesn't clear the graphics buffer (main or specified).
Somehow, the anti-aliasing of borders (graphics and rect, I suppose), when cumulated, erases the drawing.

Notice I didn't had an issue in my test code because I have a background() instruction at the start of the draw.

If I change the code to:
Code:
nt OUTPUT_WINDOW_WIDTH = 8;
int OUTPUT_WINDOW_HEIGHT = 8;
int OUTPUT_WINDOW_POSITION_X = 20;
int OUTPUT_WINDOW_POSITION_Y= 20;


int OUTPUT_WINDOW_WIDTH2 = 20;
int OUTPUT_WINDOW_HEIGHT2 = 20;
int OUTPUT_WINDOW_POSITION_X2 = 50;
int OUTPUT_WINDOW_POSITION_Y2= 20;

PGraphics outputScreen;
PGraphics outputScreen2;

void setup() {
size(500, 500);
frameRate(5);
outputScreen = createGraphics(OUTPUT_WINDOW_WIDTH, OUTPUT_WINDOW_HEIGHT, P3D);
outputScreen2 = createGraphics(OUTPUT_WINDOW_WIDTH2, OUTPUT_WINDOW_HEIGHT2, P3D);

outputScreen.beginDraw();
outputScreen.background(#dce6ee);
outputScreen.rect(1,1,2,2);
outputScreen.endDraw();

outputScreen2.beginDraw();
outputScreen2.background(#dce6ee);
outputScreen2.rect(1,1,2,2);
outputScreen2.endDraw();
}

void draw(){
background(200);
image(outputScreen, OUTPUT_WINDOW_POSITION_X, OUTPUT_WINDOW_POSITION_Y);
image(outputScreen2, OUTPUT_WINDOW_POSITION_X2, OUTPUT_WINDOW_POSITION_Y2);
}

(Reminder: keep size() call first of setup() and use numerical values)
Re: PGraphics and rect(), it only draw once
Reply #10 - Dec 6th, 2008, 5:09pm
 
ehm you only draw it once with the setup, and that's the problem.

i don't understand what do you mean about the graphic buffer.
Re: PGraphics and rect(), it only draw once
Reply #11 - Dec 6th, 2008, 7:16pm
 
Yes, because the graphics don't change...
But indeed, I see now the issue, which is a bit strange. So maybe there is a bug, or a strange side effect at least...
Code:
int OUTPUT_WINDOW_WIDTH = 10;
int OUTPUT_WINDOW_HEIGHT = 10;
int OUTPUT_WINDOW_POSITION_X = 20;
int OUTPUT_WINDOW_POSITION_Y= 20;


int OUTPUT_WINDOW_WIDTH2 = 20;
int OUTPUT_WINDOW_HEIGHT2 = 20;
int OUTPUT_WINDOW_POSITION_X2 = 50;
int OUTPUT_WINDOW_POSITION_Y2= 20;

PGraphics outputScreen;
PGraphics outputScreen2;

void setup() {
size(500, 500);
frameRate(1);
outputScreen = createGraphics(OUTPUT_WINDOW_WIDTH, OUTPUT_WINDOW_HEIGHT, P3D);
outputScreen2 = createGraphics(OUTPUT_WINDOW_WIDTH2, OUTPUT_WINDOW_HEIGHT2, P3D);
}

void draw(){
background(200);

outputScreen.beginDraw();
outputScreen.background(#dce6ee);
outputScreen.fill(0);
outputScreen.noStroke();
outputScreen.rect(1,1,2,2);
outputScreen.endDraw();
image(outputScreen, OUTPUT_WINDOW_POSITION_X, OUTPUT_WINDOW_POSITION_Y);

outputScreen2.beginDraw();
outputScreen2.background(#dce6ee);
outputScreen2.fill(0);
outputScreen2.noStroke();
outputScreen2.rect(1,1,2,2);
outputScreen2.endDraw();
image(outputScreen2, OUTPUT_WINDOW_POSITION_X2, OUTPUT_WINDOW_POSITION_Y2);
}

The display is fine, but if I reduce the first two values to 9 or below, the drawing disappears there.
P2D doesn't have this issue.
Page Index Toggle Pages: 1