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 › Writing snapshots without rendering in window
Page Index Toggle Pages: 1
Writing snapshots without rendering in window (Read 2406 times)
Writing snapshots without rendering in window
Jun 25th, 2008, 10:30pm
 
Is there a way to write snapshots without having to render the scene to a window? If so, can someone explain how this is done? Also, wouldn't this speed up the process time?
Re: Writing snapshots without rendering in window
Reply #1 - Jun 26th, 2008, 8:20pm
 
Basically, you create a PGraphics and apply the drawing operations on it.
I don't think you will gain a significant amount of time, though.
Re: Writing snapshots without rendering in window
Reply #2 - Jun 27th, 2008, 9:01am
 
Quote:
Also, wouldn't this speed up the process time?


No, since Processing already handle double-buffering, you don't need to care about rendering things in a buffer before displaying.
Re: Writing snapshots without rendering in window
Reply #3 - Jun 27th, 2008, 4:20pm
 
I wasn't thinking so much as writing into a buffer. I was thinking more along the lines of not having to render something to a window and just have it write directly to a file skipping the visual feedback given by the window.
Re: Writing snapshots without rendering in window
Reply #4 - Jun 27th, 2008, 4:30pm
 
you can do that :
Code:
PGraphics buffer = createGraphics(400, 400, P3D);
buffer.beginDraw();
buffer.background(255);
buffer.fill(250, 150, 0);
buffer.stroke(0);
buffer.rect(10, 10, 380, 380);
buffer.save("snapshot.png");
buffer.endDraw();


but, it's easier to render in the main window and save :
Code:
size(400, 400, P3D);
background(255);
fill(250, 150, 0);
stroke(0);
rect(10, 10, 380, 380);
save("snapshot.png");


more info about the save() method :
http://processing.org/reference/save_.html
Re: Writing snapshots without rendering in window
Reply #5 - Jun 27th, 2008, 5:17pm
 
It's more clear to me now. Thanks for the help.
Re: Writing snapshots without rendering in window
Reply #6 - Jun 29th, 2008, 1:24am
 
@antiplastik

as you are talking about this topic right now, ive got a question.So i dont need to open a new thread with the same question... as the drawings i do getting more complex. PDF output is not a good idea anymore. working is much to slow. I wanted to output it as a highres image but couldnt figure out how PGgraphics exactly works.

Do i have to add the name(buffer in your case) to every single command which should be drawn like, line, fill, stroke ellipse and so one? how do you handle this if youve got a lot of them? or do i just dont get how PGraphics works...?
Re: Writing snapshots without rendering in window
Reply #7 - Jun 29th, 2008, 2:56pm
 
Cedric, basically, yes, you have to tell each time in what PGraphics buffer you write: that's because you can have several buffers opened simultaneously, where you can draw same or different things, etc.
It would be nice to have an instruction telling Processing that any further graphic command will go in a given buffer, but I don't know if such command exists yet.
Re: Writing snapshots without rendering in window
Reply #8 - Jun 29th, 2008, 3:49pm
 
Ok, then i got it right but i was asking myself the same question if there is a command like that. So i guess i have to remove and add the buffer name everytime i want to switch between screenoutput and saving to a file and this takes some time if you have up to 30-40 commands.
Re: Writing snapshots without rendering in window
Reply #9 - Jun 29th, 2008, 8:07pm
 
One thing you can do:
create a flag indicating if you want drawing on screen or in a graphics buffer:
boolean bOnScreen = false;

In setup(), initialize accordingly:
 if (bOnScreen)
 {
   pg = this.g; // The PGraphics buffer of Processing itself!
 }
 else
 {
   pg = createGraphics(width, height, JAVA2D);
 }

And draw:
 if (bOnScreen)
 {
   pg.beginDraw();
 }
 pg.ellipseMode(CORNER);
 pg.image(pi, 0, 0);
 pg.stroke(0); pg.fill(20, 200, 10);
 pg.ellipse(cx, cy, sz, sz);
 pg.fill(200, 20, 20);
 pg.rect(cx, cy+30, sz/2, sz/2);
 if (!bOnScreen)
 {
   pg.endDraw();
 }

Not tested extensively, might have bad side effects, but it is an idea to explore.
Re: Writing snapshots without rendering in window
Reply #10 - Jun 30th, 2008, 1:18am
 
PhiLho  wrote on Jun 29th, 2008, 2:56pm:
It would be nice to have an instruction telling Processing that any further graphic command will go in a given buffer, but I don't know if such command exists yet.


I like this idea.

-> let's add it to the suggestions! :-)

Edit : after posting to the suggestions category, davbol showed up with a nice solution. You can read his answer here.
Re: Writing snapshots without rendering in window
Reply #11 - Jul 1st, 2008, 12:39am
 
Cool hack!
Page Index Toggle Pages: 1