p5.js icon indicating copy to clipboard operation
p5.js copied to clipboard

createGraphics issue with retina displays issue again but different

Open dnassler opened this issue 12 years ago • 13 comments

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 );
}

dnassler avatar Oct 21 '14 20:10 dnassler

thanks @dnassler. can you give the latest version of the lib a try and see if this fixes things?

lmccart avatar Oct 21 '14 21:10 lmccart

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.

dnassler avatar Oct 22 '14 13:10 dnassler

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)

lmccart avatar Oct 22 '14 14:10 lmccart

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.

dnassler avatar Oct 22 '14 14:10 dnassler

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.

dnassler avatar Oct 22 '14 14:10 dnassler

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.

dnassler avatar Oct 22 '14 15:10 dnassler

ah ok, I'll take a closer look later. thanks for helping to debug this.

lmccart avatar Oct 22 '14 19:10 lmccart

@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).

ffrappo avatar Oct 22 '14 20:10 ffrappo

@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.

lmccart avatar Oct 23 '14 18:10 lmccart

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.=

ffrappo avatar Oct 23 '14 20:10 ffrappo

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.

lmccart avatar Dec 06 '14 14:12 lmccart

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. image

saivan avatar Jun 14 '18 17:06 saivan

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

Spongman avatar Jun 14 '18 17:06 Spongman