Following some advice found on the forum here, I usually use the following method to clear/erase a PGraphics buffer:
- void erase() {
- color c = color(0,0);
- natzke.beginDraw();
- natzke.loadPixels();
- for (int x= 0; x < natzke.width; x++) {
- for (int y = 0; y < natzke.height; y++ ) {
- int loc = x + y * natzke.width;
- natzke.pixels[loc] = c;
- }
- }
- natzke.updatePixels();
- natzke.endDraw();
- }
However, for a current sketch, I have switched to a GLGraphicsOffScreenBuffer, both for speed reasons and because I was experiencing some odd PGraphics behaviour.
This doesn't work using GLGraphics - at least, it has other effects such as erasing my entire canvas, not just the graphics buffer... and I can't seem to redraw the canvas.
This is my first time using GLGraphics, so I'm not very familiar with it, but I found a clear() function in the javadoc. However, when I try to call it
- void erase() {
- color c = color(0,0);
- natzke.beginDraw();
- natzke.loadPixels();
- for (int x= 0; x < natzke.width; x++) {
- for (int y = 0; y < natzke.height; y++ ) {
- int loc = x + y * natzke.width;
- natzke.clear(0);
- }
- }
- natzke.updatePixels();
- natzke.endDraw();
- }
... it crashes my computer. Totally frozen. Now, I'm not sure that I am using it in the correct way (do I have to loadPixels, for eg.?), but I'm a little remiss to experiment right now, as I have to hard boot my laptop every time I get it wrong...
Any thoughts or experience is welcome...
~ J
EDIT:
Ok, I took it out of the two nested for loops, and it doesn't crash(freeze) my computer anymore.
But, it is still erasing everything else outside of the buffer... have to work on that. Ideas still welcome.
EDIT #2:
Got it.
- natzke.beginDraw();
- natzke.clear(0, 0, 0, 0);
- natzke.endDraw();
Was so simple, I overanalyzed it. Sorry for the false alarm..
1