Using Images From URLs

Hi,

if you would ever be so inclined, could someone please show me the correct way to load images using a url as the path. It accepts urls and returns this error so i do not know what i am doing wrong.

TypeError: Failed to execute ‘texImage2D’ on ‘WebGLRenderingContext’: Overload resolution failed.

thankyou!

Hi @s31,

would you please share your code which producing this error, so we could test and see what is ongoing ?

Cheers
— mnse

let pic;

function setup() {
  createCanvas(500, 500, WEBGL);
  pic = loadImage('https://imgur.com/gallery/9am48');
}

function draw() {
  background(205, 102, 94);
  texture(pic); 
  sphere(40);
}

returns

Hi @s31,

This is an issue with the CORS policy.

You can read more about it on those previous threads:

EDIT:

as @mnse said, it’s the url that is not the right one, it’s explained in this SO thread how you can get a direct link to an Imgur image:

1 Like

Hi @s31,

actually you are also not loading an image by that url you are using.

try this…

let pic;

function setup() {
  createCanvas(500, 500, WEBGL);
  pic = loadImage('https://i.imgur.com/9am48.png'); // real url of the image ...
}

function draw() {
  background(205, 102, 94);
  texture(pic); 
  rect(-width/2,-height/2,width,height);
}

Cheers
— mnse

3 Likes