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
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!
1