Loading...
Processing Forum
Recent Topics
All Forums
Screen name:
okike.tiqodosa
okike.tiqodosa's Profile
2
Posts
6
Responses
0
Followers
Activity Trend
Last 30 days
Last 30 days
Date Interval
From Date :
To Date :
Go
Loading Chart...
Posts
Responses
PM
Show:
All
Discussions
Questions
Expanded view
List view
Private Message
P2D, selectOutput(), save() mystics - empty image saved...
[7 Replies]
12-Apr-2013 12:31 AM
Forum:
Programming Questions
hello!
After developing a nice drawing algorithm, I decided it would be good to save the result,
but faced such misbehavior in P2D mode combined with selectOutput that the only way I can describe it is "mystics" :)
I simplified the code just to give you the idea of what's going on:
int p = 0;
void setup()
{
size(100, 100, P2D);//troublesome
//size(100,100) - no problem!
loadPixels();
noLoop();
}
void draw()
{
while (p<width*height) pixels[p++] = color(random(255));
updatePixels();
selectOutput("Save as...", "saver");//this won't work
//says "OpenGL error 1282 at top beginDraw(): invalid operation
//and saver() saves empty frame
//save("test.png");
//if uncommented, this would save the image correctly
//if you comment out selectOutput(... at the same time,
//and mystically, if both are uncommented, saver() will save
//what it's meant to save! (although the opengl errors will persist)
}
void saver(File target)
{
while (target == null) delay(200);
save(target.getAbsolutePath()+".png");
}
I hope the comments speak for themselves, but I'll try to elaborate more:
If I run the code with the standard renderer, the selectOutput() and save()
work as intended;
In P2D mode, though, if save("test.png") alone is used, it does save the result
as expected, if only at a fixed location;
If only selectOutput() is used, the saved file is blank gray, and in the console
there are errors:
OpenGL error 1282 at top beginDraw(): invalid operation
OpenGL error 1282 at bot beginDraw(): invalid operation
OpenGL error 1282 at top endDraw(): invalid operation
OpenGL error 1282 at bot endDraw(): invalid operation
And if both selectOutput() and then plain save() are called,
I get the same errors BUT the file saved via selectOutput()
contains the actual image!
This latter case baffles me pretty much.
Please demystify this for me, kind people!
load an image via selectInput and THEN set sketch size to its dimensions, using P2D ?
[2 Replies]
07-Apr-2013 01:13 PM
Forum:
Programming Questions
Hello!
I'm struggling with the subject. While I use standard renderer, it's all good.
PImage image;
void setup() {
noLoop();
selectInput("Choose an image", "inputFile");
interrupt();
size(image.width, image.height);
image(image, 0, 0);
loadPixels();
//then manipulate the pixels
}
void inputFile(File selected) {
if (selected == null) exit();
image = loadImage(selected.getAbsolutePath());
loop();
}
void interrupt() {
while (image==null) delay(200);
}
but the same code with size(image.width, image.height, P2D)
runs the lines before it multiple times and is unusable.
yes, I've read that it's the way P2D gets initialized.
I came up with the following workaround:
PImage image;
boolean alreadyLoaded;
void setup() {
noLoop();
if (!alreadyLoaded)
{
selectInput("Choose an image", "inputFile");
interrupt();
alreadyLoaded = true;
}
size(image.width, image.height, P2D);
image(image, 0, 0);
loadPixels();
//then manipulate the pixels
}
void inputFile(File selected) {....}
void interrupt() {....}
but isn't there really a cleaner soultion? I'd be very grateful if someone points out,
thanks.
«Prev
Next »
Moderate user : okike.tiqodosa
Forum