Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

createGraphics and loadPixels #1403

Closed
no-carrier opened this issue May 10, 2016 · 4 comments
Closed

createGraphics and loadPixels #1403

no-carrier opened this issue May 10, 2016 · 4 comments

Comments

@no-carrier
Copy link

no-carrier commented May 10, 2016

Hi all,
Not sure if this is a bug, but its not documented and functions very differently than Processing, which is confusing. If you use createGraphics() to draw an off-screen buffer (called buffer below), then use buffer.loadPixels(), the pixels() array gets updated with those pixels, not buffer.pixels() like in Processing. The example below demonstrates this. If this is the intended function -- it would be helpful if it was documented somewhere. Thanks!

Here is an example:

// ----------------------

var buffer;
var d;

function setup() {
createCanvas(200, 200);
buffer = createGraphics(width,height);
d = pixelDensity();
}

function draw() {
var index = (0 * width + 0) * (d * 4);

buffer.background(0, 0, 0);
buffer.loadPixels();

background(64, 255, 128);

console.log(buffer.pixels[0]); // should this be 0 (as in Processing)? logs undefined
console.log(buffer.pixels[1]); // same
console.log(buffer.pixels[2]); // same

console.log(pixels[0]); // should this be 64? logs as 0
console.log(pixels[1]); // should this be 255? logs as 0
console.log(pixels[2]); // should this 128? logs as 0

noLoop();
}

@Craigson
Copy link

Craigson commented May 12, 2016

As far as I understand it, loadPixels() only works with the default display window (I think there are plans to change this so that it applies to multiple buffers, @lmccart ? ) so using loadPixels won't have any effect on your buffer object's pixel array.

As an aside, writing to the buffer would require you do to something like this:

 buffer.background(64,255,128); 

@no-carrier
Copy link
Author

no-carrier commented May 12, 2016

Got it. As I said, I was using it the way I've used it in Processing, but now I know it that it doesn't apply to multiple buffers. Thanks!

@shiffman
Copy link
Member

loadPixels() should work with createGraphics(). We went around on this with quite a few issues I recall, @no-carrier can you confirm it's not working for you with the very latest release?

@lmccart
Copy link
Member

lmccart commented May 16, 2016

I have a new release coming hopefully today that includes the latest pixel fixes, so I'd wait a day and try with tthat one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants