createGraphics issue with retina displays issue again but different
The following code shows, incorrectly, a blue square in the upper left part of the the canvas with red otherwise on retina displays (i.e. pixel density is 2) but shows, correctly, a full blue canvas on a regular MAC desktop (pixel density is 1). This is using the latest version of p5: 0.3.9
var g
function setup() {
createCanvas(100,100);
background(255,0,0); // red
g = createGraphics(100,100);
g.background(0,0,255); // blue
noLoop();
}
function draw() {
image( g );
}
thanks @dnassler. can you give the latest version of the lib a try and see if this fixes things?
I just tried it using 0.3.10 from:
…and the problem is still there unfortunately. I also tried it with version 0.3.8 and the problem is not with that version. So this bug must have been introduced in 0.3.9. I know that version 0.3.9 fixed another bug that was related to using createGraphics and setting it to an image object which was nice. I wonder if that fix somehow had this as a side effect?
On Oct 21, 2014, at 5:26 PM, Lauren McCarthy [email protected] wrote:
thanks @dnassler https://github.com/dnassler. can you give the latest version of the lib a try and see if this fixes things?
— Reply to this email directly or view it on GitHub https://github.com/lmccart/p5.js/issues/397#issuecomment-60001625.
sorry, I wasn't very clear. could you try using this lib file? (I was waiting to push a new version to npm until we confirmed this fixes things)
That version from the link fixed it… yes!
On Oct 22, 2014, at 10:07 AM, Lauren McCarthy [email protected] wrote:
sorry, I wasn't very clear. could you try using this lib file https://github.com/lmccart/p5.js/blob/master/lib/p5.js? (I was waiting to push a new version to npm until we confirmed this fixes things)
— Reply to this email directly or view it on GitHub https://github.com/lmccart/p5.js/issues/397#issuecomment-60089821.
I think that this version fixes it but re-introduces the earlier problem…
On Oct 22, 2014, at 10:07 AM, Lauren McCarthy [email protected] wrote:
sorry, I wasn't very clear. could you try using this lib file https://github.com/lmccart/p5.js/blob/master/lib/p5.js? (I was waiting to push a new version to npm until we confirmed this fixes things)
— Reply to this email directly or view it on GitHub https://github.com/lmccart/p5.js/issues/397#issuecomment-60089821.
here is an example of what doesn't work with this fix:
function setup() {
createCanvas(100,100);
background(255,0,0); // red
g = createGraphics(width,height);
g.clear();
g.fill(0,0,255);
g.rect(0,0,width,height/2);
var tempImg = createImage(width,height);
tempImg.copy( g, 0,0, g.width,g.height, 0,0,tempImg.width,tempImg.height);
image( tempImg, 0, 0 );
noLoop();
}
function draw() {
}
Using the version from the link causes the above to show a blue rectangle over a red rectangle on the desktop... but it shows only a blue box on a retina display.
ah ok, I'll take a closer look later. thanks for helping to debug this.
@lmccart I'm new to p5.js and I was planning to force an higher resolution to canvas with css.
So I don't know if I'm missing something, but avoiding the retina management at all (this._pixelDensity = 1;) seems to solve all issues for me. I get a coherent display in all my devices and on desktop with the above test by dnassler (half blue, half red).
@frapporti yes that will definitely work as an alternative, and we're planning to add a nicer, user facing method for doing just this (disable retina scaling). it just means it may look a little blurrier on retina screens, though it will run faster.
My workaround to this usually is with css. I create my canvas @2x the final size, then set max-width and max-height on them to increase pixel density.=
I'm sure you will find some other case where we need to reopen this :), but the image copy method should be working with pixelDensity at least for now.
I think I might have found one. It seems that in the latest version, calling pg.clear() on a retina display will only clear the top left hand corner. It clears exactly one quarter of the total space, which indicates that this is also probably a pixel density issue.

@saivan I believe theclear issue was fixed in #2852 but has not been released yet.