Using PGraphics for creating textures

I asked this before, but I haven't gotten much further. This time I took a more basic approach, but I just don't get it. How can you create a texture, using PGraphics?

The stupid() function works but createTexture() doesn't.

PGraphics pg;
PImage img;

float size = 200;

void setup() {
  background(255);
  size(800, 600, P3D);
  textureMode(NORMAL);

  pg = createGraphics(100, 100, P3D);
  createTexture();
}

void draw() {
  background(255);  
  translate(width/2, height/2, 0);
  beginShape();
  texture(pg.get());
  fill(0);
  vertex(-size, -size, 0, 0, 0);
  vertex(size, -size, 0, 1, 0);
  vertex(size, size, 0, 1, 1);
  vertex(-size, size, 0, 0, 1);
  endShape();
}

void stupid(){
  pg.beginDraw();
  pg.background(255);
  pg.ellipse(pg.width/2, pg.height/2, 50, 50);
  pg.endDraw();
}

void createTexture() {
 pg.beginDraw();
 pg.background(255);
 pg.stroke(0);
 pg.noFill();
 drawCircle(width/2, height/2, 50);
 pg.endDraw();
}

void drawCircle(float x, float y, float d) {
  pg.ellipse(x, y, d, d);
  if (d > 2) {
    drawCircle(x+d/2, y, d/2);
    drawCircle(x-d/2, y, d/2);
  }
}

Answers

Sign In or Register to comment.