如何在处理中使用图像填充顶点的形状?

问题描述:

当我使用我的代码时,它说:没有uv文本坐标与vertex()调用提供。 这是我使用的代码:如何在处理中使用图像填充顶点的形状?

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(); 
} 
+1

请发布整个错误输出。 – Adonis

+1

@MatthieuSjollema您确实正在传递x,y坐标,但不是u,v纹理坐标到'vertex()'调用。签出[这个相关的答案](https://*.com/questions/44451575/processing-using-texture-inside-the-audio-waveform/44458640#44458640)更多的解释uv tex。坐标。 –

就像你的错误和乔治的评论说,用你需要在4个参数传递给vertex()功能,而不是2个参数的纹理。

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

另外请注意,你不应该加载图像的draw()功能里面,因为那使你加载相同的图像每秒60次。您应该从setup()函数加载一次。