Screen fading code doesn't work in opengl
I'm trying to make the screen slowly fade to black without ghostly residue.
I read Reas' code about this, and tried the following, which works fine in P2D or P3D but doesn't in opengl.
Is there a way to do this in opengl?
import processing.opengl.*;
void setup() {
size(400,400,OPENGL);
//size(400,400,P2D); //works fine
noStroke();
fill(255,0,0);
background(0);
}
void draw() {
fade();
ellipse(mouseX,mouseY,20,20);
}
void fade() {
int r,g,b;
loadPixels();
for (int i=0;i<pixels.length;i++) {
r=pixels[i]>>16&255;
g=pixels[i]>>8&255;
b=pixels[i]&255;
pixels[i]=color(r-1,g-1,b-1);
}
updatePixels();
}