'How do I fill a vertex' shape with an image in processing?

When I use my code it says: No uv text coordinates supplied with vertex() call. This is the code I use:

PImage img;

void setup() {
size(720, 360, P3D);
}

void draw() {
  beginShape();
  img = loadImage("image.png");
  texture(img);
  vertex(50, 20);
  vertex(105, 20);
  vertex(105, 75);
  vertex(50, 75);
  endShape();
}


Solution 1:[1]

Like your error and George's comment say, to use a texture you need to pass in 4 parameters to the vertex() function instead of 2 parameters.

From the reference:

size(100, 100, P3D);
noStroke();
PImage img = loadImage("laDefense.jpg");
beginShape();
texture(img);
vertex(10, 20, 0, 0);
vertex(80, 5, 100, 0);
vertex(95, 90, 100, 100);
vertex(40, 95, 0, 100);
endShape();

texture
(source: processing.org)

Also note that you should not be loading your image inside the draw() function, because that causes you to load the same image 60 times per second. You should load it once from the setup() function.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Glorfindel