pushMatrix on an image won't pop
in
Programming Questions
•
1 year ago
Sorry, this is a total beginner question. Please excuse my ignorance.
I'm trying to process the pixels in an image. I want to be able to make my own filters that I can apply live. But the pushMatrix and popMatrix functions are giving me some guff.
So I have a series of images inside of an array. They are called in a slideshow type functionality, and then effected live by pressing keys. I'm trying to make a image mirror itself right down the middle when I press a button, and then let go when I let go of the key. The program is pretty big (and ugly), so I'm going to only show the relevant code.
- pushMatrix();
- images[imageIndex].loadPixels();
- int imageWidth = images[imageIndex].width;
- int imageHeight = images[imageIndex].height;
- // Begin loop for width
- for (int x = 0; x < images[imageIndex].width; x++) {
- // Begin loop for height
- for (int y = 0; y < images[imageIndex].height; y++) {
- images[imageIndex].pixels[y*images[imageIndex].width+x] = images[imageIndex].pixels[(images[imageIndex].width - x - 1) + y*images[imageIndex].width]; // Reversing x to mirror the image
- }
- }
- images[imageIndex].updatePixels();
- popMatrix();
I thought that putting the matrix manipulation inside push and pop would make it "undo-able", but I clearly don't have a good grasp of how push and pop work.
What am I doing wrong? Any help is greatly appreciated.
1