Move image between textures
in
Programming Questions
•
3 years ago
Hai folks!
I'm trying to move two images between two textures, the problem is that the framerate is dropping to around 10 when doing this, and I eventually will need to move more than one image, so I'm guessing i'm doing something wrong here. :-)
Here's my snip of code so far:
- import processing.opengl.*;
- PImage a;
- PImage b;
- void setup(){
- size(800, 800, OPENGL);
- noStroke();
- a = loadImage("tex1.png");
- b = loadImage("tex2.png");
- }
- void draw(){
- background(0);
- updateTextures(a, b, 1);
- beginShape();
- texture(a);
- vertex(40, 80, 0, 0);
- vertex(320, 20, b.width, 0);
- vertex(380, 360, b.width, b.height);
- vertex(80, 380, 0, b.height);
- endShape();
- beginShape();
- texture(b);
- vertex(40, 430, 0, 0);
- vertex(350, 420, b.width, 0);
- vertex(330, 760, b.width, b.height);
- vertex(50, 780, 0, b.height);
- endShape();
- }
- void updateTextures(PImage img1, PImage img2, int speed){
- img1.loadPixels();
- img2.loadPixels();
- for(int i = 0; i < (img1.width * img1.height) - img1.width; i++) {
- img1.pixels[i] = img1.pixels[i + img1.width];
- if(i < img1.width){
- img1.pixels[((img1.width * img1.height) - img1.width) + i] = img2.pixels[i];
- }
- img2.pixels[i] = img2.pixels[i + img2.width];
- }
- img1.updatePixels();
- img2.updatePixels();
- }
Any help would be very much appreciated! - Thanks!
1
