codeanticode / tablet

Tablet is a library for using pen tablets from Processing.
http://processing.andrescolubri.net/libraries/tablet/
Other
24 stars 2 forks source link

oldest pen values are returned with OpenGL renderer #6

Open codeanticode opened 8 years ago

codeanticode commented 8 years ago

From an email report:

"In P3D and P2D, the library seems to be queuing up all of the intermediate pen values between each draw() call - but when any of tablet.getPressure(), tablet.getPenKind(), tablet.getX(), tablet.getY() etc are called, only the oldest value in the queue is popped. Whereas with the default renderer, it just return the current pen state."

Discussion here.

hamoid commented 8 years ago

I'm getting the same problem. I worked around it creating a second Processing sketch (non P2D/P3D) that sends the pressure to the P2D program via UDP. Very much a hack, but I needed this :)

// SENDER
import codeanticode.tablet.*;
import hypermedia.net.*;

UDP udp;
Tablet tablet;
byte[] b = new byte[3];

void setup() {
  size(640, 480);
  frameRate(30);
  tablet = new Tablet(this);
  udp = new UDP(this, 6100);
  stroke(255);
}
void draw() {
  background(0);
  float p = 255 * tablet.getPressure();
  ellipse(mouseX, mouseY, p, p);
  b[0] = byte((int)p);
  b[1] = byte((int)(255.0 * mouseX / width));
  b[2] = byte((int)(255.0 * mouseY / height));
  udp.send(b, "localhost", 6150);
}

// RECEIVER (P2D)
import hypermedia.net.*;

UDP udp;
int p = 0;
int x = 0;
int y = 0;

void setup() {
  size(256, 256, P2D);
  udp = new UDP( this, 6150 );
  udp.listen( true );
  stroke(255);
}

void draw() {
  background(0);
  ellipse(x, y, p, p);
}

void receive( byte[] data ) {
  p = data[0] & 0xFF;
  x = data[1] & 0xFF;
  y = data[2] & 0xFF;
}
codeanticode commented 8 years ago

@hamoid will try to get fix this asap :-)

conorhub commented 7 years ago

I believe I'm having the same issue. Changing a sketch I had from the default renderer in Processing 3.2.2 to P2D or P3D caused all sorts of strange issues, most notably my simple paint utility (based off the bundled example) no longer drew anything to the canvas.

I finally tracked it down to the tablet plugin returning 0.0 for tablet.getPressure() until I turn the default renderer back on. It then returns expected values. Occasionally I got it to work by waving my mouse over the sketch first and then trying my Wacom.

EDIT:

Just saw that one of your more recent releases states 'adds support for the OpenGL renderers (P2D/P3D)', which makes me wonder what I've done to retrigger this. I've just confirmed I'm using the latest (2.0-alpha3 (7)) release on OSX 10.12. Also, I never thanked you for creating this in the first place - it's much appreciated and was working great before I switched renderer.

conorhub commented 7 years ago

I simplified the issue down to a replicatable example in the below code:

import codeanticode.tablet.*;

Tablet tablet;

PGraphics drawCanvas;

void setup() {
  size(1080, 1080, P2D);
  drawCanvas = createGraphics(width, height, P2D);
  tablet = new Tablet(this);
  drawCanvas.smooth(8);
}

void draw() {
  drawCanvas.beginDraw();
  if (tablet.getPressure() > 0.0) {
    println("Pressure seems to be working");
  }
  //drawCanvas.strokeWeight(5);
  drawCanvas.strokeWeight(25 * tablet.getPressure());

  if (mousePressed) {
    drawCanvas.line(mouseX, mouseY, pmouseX, pmouseY);
  }      
  drawCanvas.endDraw();
  image(drawCanvas,0,0);
}

It will (seemingly) randomly decide whether to return pressure from the Wacom tablet on each launch. If I try and use the tablet first, it rarely works, returning 0.0 for pressure for the duration. If I try and draw with my mouse, then draw with the tablet, sometimes it will work, sometimes it won't. If it works at all, it works for the duration. It's one or the other.

If I remove P2D and use the default renderer it works every time. Wacom Intuos 3 works perfectly in other software every time.

conorhub commented 7 years ago

I've managed to make zero progress with this, unfortunately, but am very keen to help see it solved. Even a message from the developer stating this is never going to be addressed would be appreciated. Thanks in advance.

codeanticode commented 7 years ago

Hi, I'm keeping an eye on this. I can see my last comment from Jan 26, hopefully will be able to spend some time on it. Thanks for your feedback!

conorhub commented 7 years ago

Very happy to see that this is being watched. Thank you codeanticode. I can appreciate that you're busy.

codeanticode commented 7 years ago

@conorhub I think the problem you are reporting (no pressure returned) is different from what we were discussed originally in this thread (although is also related to the use of the OpenGL renderers). I sometimes get no pressure with the P2D/P3D renderers, but it is definitely not very often (perhaps 1 out of 10).

@hamoid I have been running some tests, but it is hard for me to pinpoint the exact issue. I put together this test sketch:

import codeanticode.tablet.*;

Tablet tablet;

boolean useCallback = false;
float pressure;
int levelEventCalls;

String renderer = JAVA2D;
//String renderer = P2D;

void setup() {
  size(720, 720, renderer);
  smooth(8);
  tablet = new Tablet(this);
  textFont(createFont("Arial", 30));
  background(180);
}

void draw() {
  stroke(0);
  if (useCallback) strokeWeight(25 * pressure);
  else strokeWeight(25 * tablet.getPressure());  
  if (mousePressed) {
    line(mouseX, mouseY, pmouseX, pmouseY);
  }      

  noStroke();
  fill(255, 0, 0);
  rect(0, 0, width, 50);
  fill(255);
  text(frameCount + " - " + levelEventCalls, 20, 40);  
}

void keyPressed() {
  if (key == ' ') background(180);
  else if (key == 'c') {
    useCallback  = !useCallback;
    println("Using callback", useCallback);
  }
}

void penLevelEvent(Tablet t) {
  levelEventCalls++;
  pressure = t.getPressure();
}

where the pressure can be obtained either by calling getPressure() in draw(), or in the level event callback. I observed that, at least in my system, the callback function is called around twice as frequently as the draw() function... That being said, I'm unable to notice a difference in the smoothness of the lines between JAVA2D and P2D.

BTW, are you on Windows, Mac, or Linux?

hamoid commented 7 years ago

Thanks @codeanticode ! I tried your program and no pressure data is received when using P2D. The right counter is stuck at 0. I use ArchLinux with i3 tiling window manager, a Wacom Intuos 1 (I think), Intel 4600 graphics. With Java2D it works as expected.