How to set texture correctly into a warped shape (for a projection mapping)

Hi guys, I'm doing a simple projection mapping and I need to warp the frame buffer a little. I wrote this code:

PGraphics pg;

PVector a, b, c, d;

void setup() {
  size(600, 600, OPENGL);
  smooth();

  pg = createGraphics(width, height, OPENGL);

  a = new PVector(0, 0);
  b = new PVector(width, 0);
  c = new PVector(width, height);
  d = new PVector(0, height);
}

void draw() {
  background(0);

  pg.beginDraw();
  pg.background(0);
  for (int i = 0; i < pg.width; i+=10) {
    pg.strokeWeight(2);
    pg.stroke(255);
    pg.line(i, 0, i, pg.height);
  }
  pg.endDraw();

  beginShape();
  texture(pg);
  noStroke();
  vertex(a.x, a.y, 0, 0);
  vertex(b.x, b.y, pg.width, 0);
  vertex(c.x, c.y, pg.width, pg.height);
  vertex(d.x, d.y, 0, pg.height);
  endShape(CLOSE);

  //image(pg, 0, 0, width, height);
}

void mouseDragged() {
  if (dist(mouseX, mouseY, a.x, a.y) < 50) {
    a.x = mouseX;
    a.y = mouseY;
  } else if (dist(mouseX, mouseY, b.x, b.y) < 50) {
    b.x = mouseX;
    b.y = mouseY;
  } else if (dist(mouseX, mouseY, c.x, c.y) < 50) {
    c.x = mouseX;
    c.y = mouseY;
  } else if (dist(mouseX, mouseY, d.x, d.y) < 50) {
    d.x = mouseX;
    d.y = mouseY;
  }
}

but the result is a not correct proportional texture. http://i.imgur.com/9k7YIaV.png

How can I set correctly this texture? Thanks

Answers

  • Answer ✓

    Known problem, google 'affine texture'.

    I think the general solution is to cut the shape up into smaller pieces. I think I've also previously solved it using low-level opengl calls, proper QUADs rather than processing's shapes. But I'm not sure how much of an option that is.

  • This discussion might help.

Sign In or Register to comment.