Problem with beginShape(QUADS)

In one of my previous question it was suggested that I use beginShape(QUADS) to display an image. I was unsure what the third and fourth arguments in the vertex(); were after that, so I decided to experiment. This is my code, but it does not display an image at all.

PImage blob;
void setup() {
  size(800,800,P2D);
  blob = loadImage("ASD.jpg");
}
void draw() {
  background(255);
  beginShape(QUADS);
  texture(blob);
  noStroke();
  vertex(100,100,0,0);
  vertex(100,200,0,1);
  vertex(200,200,1,1);
  vertex(200,100,1,0);
  endShape();
}

If someone can explain to me what the 0s and 1s mean as the 3rd and 4th arguments in the vertexes of a beginShape(QUADS) function, that would be awesome!

Answers

  • edited September 2017

    https://www.processing.org/reference/vertex_.html

    u: float: horizontal coordinate for the texture mapping

    v: float: vertical coordinate for the texture mapping

  • You need to set the texture mode to normalized.

    That is probably displaying a quad but you're texturing it with the top left pixel of the image

  • According to the example, the u and v stand for pixel numbers. But the example that koogs gave in my previous question used 1s and 0s. What do the 0s and 1s stand for?

  • Answer ✓

    the coordinates used for u and v are specified in relation to the image's size in pixels

    relation here could mean 1 = 100 % and 0 = automatic.

    reference for vertex

    This function is also used to map a texture onto geometry. The texture() function declares the texture to apply to the geometry and the u and v coordinates set define the mapping of this texture to the form. By default, the coordinates used for u and v are specified in relation to the image's size in pixels, but this relation can be changed with textureMode().

    https://www.processing.org/reference/vertex_.html

    Also see reference textureMode

    Sets the coordinate space for texture mapping. The default mode is IMAGE, which refers to the actual coordinates of the image. NORMAL refers to a normalized space of values ranging from 0 to 1. This function only works with the P2D and P3D renderers.

    With IMAGE, if an image is 100 x 200 pixels, mapping the image onto the entire size of a quad would require the points (0,0) (100, 0) (100,200) (0,200). The same mapping in NORMAL is (0,0) (1,0) (1,1) (0,1).

    https://www.processing.org/reference/textureMode_.html

Sign In or Register to comment.