We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Can not get pixel color at mouse location if I use P2D or noLoop(). But I need to use these two in other project.
void setup() {
size(500, 150, P2D);
rectMode(CORNER);
noStroke();
}
void draw() {
for (int i=0; i< 10; i++) {
fill((color) random(#000000));
rect(i*50, 0, 50, 150);
}
noLoop();
}
void mouseClicked() {
loadPixels();
color c = pixels[mouseY*width+mouseX];
println(hue(c), saturation(c), brightness(c));
}
Answers
I did some tiny mods in order to run in my Processing v2.0.2 here. And all of a sudden, it was fixed alright! :-/
so you have to loadPixels() before executing noLoop() ?
I've transfered loadPixels() from mouseClicked() into draw().
B/c there was no need to keep updating
pixels[]
while canvas isn't being modified anyways!Seems like that modification ended up being important for OPENGL modes like P2D & P3D!
JAVA2D has a more predictable behavior and doesn't care about these strange fixes!
And whether we place noLoop() in setup() or in draw() doesn't matter!
Callback draw() is run at least once anyways! And also for each resize()!