Can is use setTexture() for PShape from SVG?

edited November 2015 in Questions about Code

Does setTexture() work for PShapes that are created from SVG-files?
I know i can use texture() between beginShape() and endShape().
And it works for PShapes that are created with createShape().

PShape shp;
PGraphics tex;
void setup() {
  size(300, 150);  
  shp = loadShape("https://upload.wikimedia.org/wikipedia/commons/8/88/Blue_oval.svg");

  // create a simple PGraphics as texture
  tex = createGraphics(100, 100);
  tex.beginDraw();
  tex.background(200, 0, 0);
  for(int i =0; i<100;i+=3){
    tex.line(i,0,i, 100);
  }
  tex.endDraw();
}

void draw() {

  background(255);

  image(tex, 10, 10);

  shp.disableStyle();
  shp.setTexture(tex);
  shape(shp, 150, 50);
}

This way it doesn't work and i have no idea where to set u/v-coordinates.
A workaround would be to use a mask, but maybe I'm just missing something and there is an easy way to handle this.

Sign In or Register to comment.