Loading...
Logo
Processing Forum
Hi,

I'm having an issue where I'm drawing strokes with a png brush using pgraphics (and the png i am using is fully transparent), but the bounding box/frame of the png is being drawn. See attached image:



This is the PGraphics routine: 

Copy code
  1. paint.beginDraw();
  2.   //paint.background(255);
  3.   //paint.tint(255, 128);
  4.   //paint.blend(paint, 0, 0, paint.width, paint.height, 0, 0, paint.width, paint.height, EXCLUSION);
  5.   paint.image(brush1, gmlX * width, gmlY * height);
  6. paint.endDraw();
I've tried a few different things (as you can see from the commented lines), such as setting the background within the PGraphics buffer, tints, and blends, but no difference...

My sketch renderer is set to OPENGL (though I've tried P3D, with no difference), and my PGraphics is P2D (though again, I've tried P3D, with no difference... 

I've also browsed through the forum, and none of the PNG issues posted really seemed to cover this issue...

So, I'm open to thoughts/ideas !! ??? Thanks... 

~ J

Replies(12)

Try JAVA2D mode in your PGraphics.
I have. It throws an unspecified Null Pointer Exception and my sketch won't run...
A Null Pointer Exception is never "unspecified"... You get a stack trace with it, that points to the line where the NPE happened.
And I doubt the issue with the NPE came from the JAVA2D mode, it was probably more with an issue in your code, that you might have solved later.
Advice: try isolating the brush drawing code in a simple, standalone sketch, to experiment and see if the issue disappear. If not, you will have some code to show us so we can see what is going wrong...
I know, but it's not highlighting anything... 

And I have isolated the code already, with the same results.

CODE

Copy code
  1. import processing.opengl.*;

  2. PImage brush;
  3. PGraphics paint;
  4. int touch = 0;

  5. void setup() {
  6.  size(400, 400, OPENGL); 
  7.  brush = loadImage("000-brush.png");
  8.  paint = createGraphics(width, height, JAVA2D);
  9. }

  10. void draw() {
  11.   background(0);
  12.   if(touch == 1) {
  13.     paint();
  14.   }
  15.   image(paint, 0, 0);
  16. }
  17. void mouseDragged() {
  18. touch = 1;
  19. }

  20. void mouseReleased() {
  21.   touch = 0;
  22. }

  23. void paint() {
  24.   paint.beginDraw();
  25.   paint.image(brush, mouseX, mouseY);
  26.   paint.endDraw(); 
  27. }

ERROR

Exception in thread "Animation Thread" java.lang.NullPointerException
at processing.opengl.PGraphicsOpenGL$ImageCache.rebind(PGraphicsOpenGL.java:1002)
at processing.opengl.PGraphicsOpenGL.bindTexture(PGraphicsOpenGL.java:832)
at processing.opengl.PGraphicsOpenGL.renderTriangles(PGraphicsOpenGL.java:755)
at processing.core.PGraphics3D.endShape(PGraphics3D.java:652)
at processing.core.PGraphics.endShape(PGraphics.java:1242)
at processing.core.PGraphics.imageImpl(PGraphics.java:2900)
at processing.core.PGraphics.image(PGraphics.java:2756)
at processing.core.PApplet.image(PApplet.java:8615)
at PNGtest.draw(PNGtest.java:39)
at processing.core.PApplet.handleDraw(PApplet.java:1610)
at processing.core.PApplet.run(PApplet.java:1506)
at java.lang.Thread.run(Thread.java:680)

I am getting similar error messages with every renderer when I have my PGraphics set to JAVA2D... 
You have a NPE because you draw with a fresh PGraphics where nothing have been drawn yet. Not sure why...
Anyway, if you add the following line after the creation of your PGraphics, the NPE goes away:
Copy code
  1. paint.beginDraw(); paint.background(0); paint.endDraw();
In setup() ??

(And are you not sure why the NPE shows up, or why I 'draw with a fresh PGraphics where nothing has been drawn yet ?? )

Ok, if I do that the NPE goes away, and I can set the PGraphics to JAVA2D, but the issue with the transparency persists...

thx...

" the issue with the transparency persists"
Well, in your sketch, the brush is transparent, I don't see what issue you have there. Or is your sketch not showing what you do in the real sketch?

PS.; a simple paint.beginDraw(); paint.endDraw(); is enough to get rid of the NPE, no need for painting there.
Ok, well my assumption is that with a png with a transparent background/canvas, it would only draw the opaque elements of the png, and not any type of border/bounding box... am I wrong in that expected behaviour ?

PS. Ok, thanks. Any idea why that happens ?
I tested / improved your sketch by making the paint graphics smaller than the sketch's area and painting it at 20, 20, it seems to illustrate better your intent (keeping intact the sketch's area, drawing transparently over a small area).

I think it can be seen as a bug in Processing, createGraphics doesn't fully do an initialization of the object, so it isn't ready yet for painting. Then again, it can be seen as a bad / useless idea to paint a virgin PGraphics... Particularly if it aims to be fully transparent.
But that still doesn't explain the behaviour that I am seeing... 

(is it clear what I am expecting to see? is it expected what I am expecting to see?)

I'll file a bug about the initialization issue...
I got this working... I remade the PNG's, perhaps I was doing something wrong in PS... apologies, and thanks.
Is there any way to use OPENGL renderer as well as get transparent PNGs? I need some sort of transparency for images that I need to stretch/skew, and the non OPENGL renderers warp the image so that they're unusable.