set(x, y, color) in GLGRAPHICS mode
in
Contributed Library Questions
•
1 year ago
Using set(x, y, color) in GLGRAPHICS mode decrease framerate from 60fps to 10. I have tried also use pixels[], but result is same.
"Setting the color of a single pixel with set(x, y) is easy, but not as fast as putting the data directly into pixels[]. The equivalent statement to "set(x, y, #000000)" using pixels[] is "pixels[y*width+x] = #000000". You must call loadPixels() to load the display window data into the pixels[] array before setting the values and calling updatePixels() to update the window with any changes."
Please put this code into GLGRAPHICS without loosing performance..
- //import processing.opengl.*;
//import codeanticode.glgraphics.*;
PImage img, dest;
color[] col = new color[480000];
void setup() {
size(1600, 600, P2D);
//size(1600, 600, GLConstants.GLGRAPHICS);
img = loadImage("landscape.jpg");
img.loadPixels();
for (int i = 0; i < 480000; i++) {
col[i]=img.pixels[i];
}
dest = createImage(800, 600, RGB);
dest.loadPixels();
for (int i = 0; i < 480000; i++) {
dest.pixels[i]=col[480000-i-1];
}
}
void draw() {
for (int i = 0; i < 7000; i++) {
int px=int(random(0, 800));
int py=int(random(0, 600));
dest.set(px, py+int(random(0, 1)), color(255, 0, 0));
//dest.pixels[px + 800*(py+int(random(0, 1)))] = #F00000;
//dest.updatePixels();
}
image(img, 0, 0);
image(dest, 800, 0);
println(frameRate);
}
1