Assigning Pixels Vertically Flipped in P2D #5013

Closed
KevinWorkman opened this Issue Apr 20, 2017 · 0 comments

Comments

Projects
None yet
2 participants
@KevinWorkman

This Stack Overflow question pointed out a strange behavior. Running this program:

PGraphics f;
void setup() {
  size(500, 500, P2D);
  f = createGraphics(width, height, P2D);
}

void draw() {
  background(0);
  rect(mouseX, mouseY, 100, 100);
  copyPixels(f); 
  image(f, 0, 0);
}

void copyPixels(PGraphics f) {
  loadPixels();
  f.loadPixels(); 

  for (int i = 0; i < pixels.length; i++) {
    color p = pixels[i];
    f.pixels[i] = p;
  }
  f.updatePixels();
}

I would expect this to simply show a rectangle wherever the mouse is. The copyPixels() function should be a no-op, since it's just copying the pixels from the screen to a buffer and then showing the buffer on the screen.

Instead, what happens is the rectangle is shown flipped vertically. If the mouse is at the top of the screen, the rectangle is at the bottom of the screen, and vice-versa. My best guess is that this has something to do with P2D being OpenGL, and OpenGL having an origin at the bottom instead of the top?

Note that this problem goes away in the default renderer, or if you just do f.pixels = pixels instead of using a for loop.

Am I missing something with how the pixels array works?

codeanticode added a commit to processing/processing-android that referenced this issue Apr 23, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment