Dear people,
probably the question is pretty simple and maybe I am just blind. Unfortunately I don’t manage to apply an Image as texture for a PGraphic. In my original code the PGraphic is used in several functions, which works out. Then I tried to apply a texture, but didn’t manage. I never worked with textures before, so maybe my mistake is really basic. I now tried to rebuild the code step by step, implementing texture form the beginning. Already at the step shown below, I don’t get an image anymore. All that is shown is the black background. I’d be very grateful if someone could help me finding my mistake.
PImage Gold;
PGraphics triangle;
void setup(){
size (1024, 800, P2D);
frameRate(30);
background(0);
noCursor();
//PGraphics:
triangle = createGraphics(width,height);
//PImage
Gold = loadImage("Gold.jpg");
}
void draw(){
translate(width/2, height/2);
//unfortunately the texture doesn't apply to the PGraphic
triangle.beginDraw();
triangle.background(0,0);
triangle.beginShape();
triangle.texture(Gold);
triangle.vertex(0, 0, mouseX, mouseY);
triangle.vertex(500, 0, 500, 0);
triangle.vertex(0, 500, 0, 500);
triangle.endShape(CLOSE);
triangle.endDraw();
image(triangle, 0, 0);
/* PGraphic works like this
triangle.beginDraw();
triangle.background(0,0);
triangle.beginShape();
triangle.fill(255,0,0);
//triangle.texture(Gold);
triangle.vertex(0, 0);
triangle.vertex(500, 0);
triangle.vertex(0, 500);
triangle.endShape(CLOSE);
triangle.endDraw();
image(triangle, 0, 0);
*/
/* the gold texture works in here
beginShape();
texture(Gold);
vertex(0, 0, mouseX, mouseY);
vertex(500, 0, 500, 0);
vertex(0, 500, 0, 500);
endShape(CLOSE);
*/
}