We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I am not sure, is there any tricky procedure I am forgetting here? Using masks seems to result on same results. I am not sure if PGraphics was designed for this, but later I wanted to draw other things inside the plane, not just the plane itself.
PGraphics plane;
void setup() {
size(300, 300, P3D);
plane = createGraphics(100, 100, P2D); // also tried P3D, JAVA2D and none
}
void draw() {
background(200);
pushMatrix();
translate(width/2, height/2, -100);
rotateX( radians(15) );
rotateY( radians( frameCount ) );
drawCross();
drawPlane();
translate(-20,20,-20);
drawPlane();
popMatrix();
}
void drawPlane() {
plane.beginDraw();
//plane.clear();
//plane.background(0,0);
plane.fill(255);
plane.beginShape();
plane.vertex(20, 0);
plane.vertex(100, 0);
plane.vertex(100, 100);
plane.vertex(0, 100);
plane.endShape();
plane.endDraw();
image(plane, -50, -50);
}
void drawCross() {
stroke(0);
strokeWeight(1);
int r = 20;
line(0, 0, r, 0);
line(0, 0, 0, r);
rotateY(HALF_PI);
line(0, 0, r, 0);
}
Answers
You haven't actually told us what the problem is. What exactly does this code do? What exactly do you expect it to do? How exactly are those two things different?
Sorry. The plane I am drawing at drawPlane is not a rectangle. One side is a slope. But instead of recognizing this shape, PGraphics is rendering the actual shape It intended to inside a rectangle and filling the area where it should be transparent with the background color. It is visible if rendered over other elements.
This is processing 3.0.1
I have seen there are some commits on github regarding PGraphics but I can't compile it.
Ah, I see what you are talking about now. When your non-rectangle rotates, the back is occluded -- there is a wedge, where the rectangle would be (but isn't), that clips out what is behind it.
I'm seeing this on Processing 3.2.1 -- so I don't think your issue relates to recent version changes.
Using PShape should fix this, allows for real non-rectangular shapes.
Thanks for the feedback. Could it be an OpenGL issue?
thanks for the idea, but I am using PGraphics as a container to draw other things inside of it. Isn't it a PShape inside my PGraphics in between the lines plane.beginShape() and plane.endShape()? If so, PGraphics is failing to be used as a container, right?
i worry that the createGraphics(100, 100) is giving you a rectangle. and regardless of what you do to that rectangle, filling it with transparent, it's still a rectangle. (it's filling it with background rather than transparency, by the look of things)
iirc there is a hint() that you can apply to get it to treat transparent parts better, if slower. hint() is under documented though and i'm not sure what the hint is
DISABLE_DEPTH_MASK
DISABLE_DEPTH_TEST
ENABLE_DEPTH_SORT
you have a shape on a PGraphics which is different, in some way i'm not sure i can explain, from a shape inside a PShape. (the latter is a collection of polygons, the former is a drawing of polygons on a rectangular image?)
there's a createImage() call as well, which lets you specify ARGB as the 3rd argument which might treat transparency better.
tbh i get confused with all this create*() stuff.
Thanks for the suggestions Koogs, but for my purpose, I really needed to find a way to use a container and I was avoiding Image, even if I kind of understand Graphics derives from it. In my head, manipulating elements such as shapes, rectangles, etc inside PGraphics is different if I try to do same thing with PImage, right?
I came to a very ridiculous solution in terms of what? too many lines to do something that supposed to be simple (set a transparency) on a irregular shape inside PGraphics. I think the code is working perfectly but, again, I am pretty sure this is NOT going to be in best practices manual.
apparently works if camera moves too, but didn't have time to test now. maybe "center" must be updated, and implement the rot() as right now works only on rotations around Y axis.