OpenGL slow, P2D fast?
in
Programming Questions
•
3 years ago
Greetings!
The following code fades an image (src) to white, and then fades back from white with a new image (dest). It's reasonably fast using P2D, but with OpenGL the frame rate plummets down to around 20 FPS. Why is that? Any thoughts or suggestions to improve this code is greatly appreciated.
- src.loadPixels();
- dest.loadPixels();
- int totalColor = src.width * src.height * 3 * 255;
- int currentTotal = 0;
- // fade the source image to white
- for (int i = 0; i < src.width * src.height; i++) {
- color rgb = src.pixels[i];
- int r = (rgb >> 16) & 0xFF;
- int g = (rgb >> 8) & 0xFF;
- int b = rgb & 0xFF;
- currentTotal += (r + b + g);
- if (currentTotal < totalColor && !stageTwo) {
- r += speed;
- g += speed;
- b += speed;
- color fin = color(r, g, b);
- src.pixels[i] = fin;
- }
- else {
- stageTwo = true;
- }
- // fade in the new image
- if (stageTwo) {
- color picked = src.pixels[i];
- color target = dest.pixels[i];
- if (((picked >> 16) & 0xFF) > ((target >> 16) & 0xFF)) r -= speed;
- if (((picked >> 8) & 0xFF) > ((target >> 8) & 0xFF)) g -= speed;
- if ((picked & 0xFF) > (target & 0xFF)) b -= speed;
- src.pixels[i] = color(r, g, b);
- currentTotal -= (r + b + g);
- }
- }
- src.updatePixels();
- dest.updatePixels();
1