We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › PGraphics Offscreen P3D context and zbuffer
Pages: 1 2 
PGraphics Offscreen P3D context and zbuffer (Read 4078 times)
PGraphics Offscreen P3D context and zbuffer
Jan 8th, 2007, 8:36am
 
Hello.

The following code acts a bit odd. It seems as though the depth/zbuffer is empty when using a P3D offscreen context with PGraphics:

Note the fill colors do not work, and when moving the mouse the offscreen context(s) inherit the background color as a fill color when drawn.

I am assuming I am doing something wrong. Id love to know what.

Processing 123/OS X 10.4.8 latest drivers, Macbook Pro.

Code:

//create offscreen graphics buffers
PGraphics context1;
PGraphics context2;

void setup()
{
 size(300,300,P3D);
 
 //initialize our offscreen graphics buffers
 context1 = createGraphics(width-20,height-20, P3D);
 context2 = createGraphics(width-20,height-20, P3D);
}

void draw()
{
 background(mouseY,0,0);
 lights();
 
pushMatrix();
translate(58, 48, 20);
rotateY(0.5);
fill(200,0,200);
stroke(200,0,200);
box(40);
popMatrix();
 
 if(mousePressed)
 {
   //only draw our contexts if we need them..
   context1Draw();
   context2Draw();
   noTint();
   image(context1,10,10);
   tint(0,0,0,mouseX);
   image(context2,10,10);
 }
}

void context1Draw()
{
 context1.beginDraw();
 context1.background(200);
 context1.lights();
 context1.fill(200,200,0);
 context1.stroke(200,200,0);
 context1.translate(58, 48, 0);
 context1.rotateY(0.5);
 context1.box(40);
 context1.endDraw();  
}

void context2Draw()
{
 context2.beginDraw();
 context2.background(100);
 context2.lights();
 context2.fill(0,0,200);
 context2.stroke(0,0,200);
 context2.translate(58, 48, 0);
 context2.rotateY(-0.5);
 context2.sphere(40);
 context2.endDraw();
}

Re: PGraphics Offscreen P3D context and zbuffer
Reply #1 - Jan 17th, 2007, 9:55pm
 
.... Anyone?
Re: PGraphics Offscreen P3D context and zbuffer
Reply #2 - Jan 17th, 2007, 10:59pm
 
If you're expecting the offscreen P3D's zbuffer to be used when you do image(context1...) that's your problem, when you use image() the zbuffer is ignored, and the contect1/2 is treated like a PImage, i.e. just an array of pixels. What 3D shapes/etc were used to create them is ignored.
Re: PGraphics Offscreen P3D context and zbuffer
Reply #3 - Jan 17th, 2007, 11:24pm
 
Did you try the example? Its clearly behaving incorrectly. Perhaps I have my terminology wrong, but the clear color of my other contexts are somehow being inherited by the fill color of the main context. The shapes I draw in my contexts have alpha values when they should be filled opaquely.

Apologies if this is incorrect, however I am copying the code almost verbatim from the help files/examples, and the documentation clearly uses P3D renderer.

Thanks.
Re: PGraphics Offscreen P3D context and zbuffer
Reply #4 - Jan 18th, 2007, 12:10am
 
Sorry, I see what you mean now.
And it looks like it may be more significant than just fill being translated over, your 3D shapes are actually being treated as transparent.

I've managed to reduce your code to a much more minimal version that shows that it's definitely a bug:
Code:
PGraphics context1;

void setup()
{
size(300,300,P3D);
context1 = createGraphics(width-20,height-20, P3D);
}

void draw()
{
/* background(mouseY,0,0);*/
stroke(0,255,0);
line(0,0,width,height);
context1.beginDraw();
context1.background(0,0,0);
context1.fill(0,0,255);
context1.stroke(200,0,0);
context1.translate(60, 60, 0);
context1.box(40);
image(context1,0,0);
}


As you can see the green line is not visible behind the background part of context1, but is behind the box.
Re: PGraphics Offscreen P3D context and zbuffer
Reply #5 - Jan 18th, 2007, 12:21am
 
Thanks for taking the time to look at the sketch. This is exactly what I was seeing as well. Its a shame, as it would make it much easier to use processing as a realtime performance tool, building transitions, disolves and effects 'plugins' via render to context would be an elegant solution. I am glad however its not just me.

Apologies for the imprecise terminology. Hopefully this will be fixed soon, it could prove to be an involauable function (quite similar to render to texture in the OpenGL world.)

Thanks,
Re: PGraphics Offscreen P3D context and zbuffer
Reply #6 - Jan 18th, 2007, 1:55am
 
johng, thanks for tracking that down.. could you post that snippet in the bugs db? (it's really helpful to have short bits like that because it makes the problem very clear...)

i believe it's related to the other createGraphics() issues, but it gives me another clue while i'm trying to make the fix.
Re: PGraphics Offscreen P3D context and zbuffer
Reply #7 - Jan 18th, 2007, 2:07am
 
Ive actually posted in the bugs db earlier

http://dev.processing.org/bugs/show_bug.cgi?id=482

Thanks.
Re: PGraphics Offscreen P3D context and zbuffer
Reply #8 - Jan 18th, 2007, 12:57pm
 
I've added the minimal code to that bug.
Re: PGraphics Offscreen P3D context and zbuffer
Reply #9 - Jan 18th, 2007, 5:59pm
 
great, thanks guys. i've verified that indeed the problem is that the non-background pixels are being set, but their opacity is not. my guess is that this is an artifact of all surfaces being opaque prior to the wider use of createGraphics(), so it's one of those things i just need to iron out.
Re: PGraphics Offscreen P3D context and zbuffer
Reply #10 - Jan 18th, 2007, 6:08pm
 
Thanks so much for the response. I am glad it seems (knock on wood..), that its a fairly straightforward fix. I look forward to the next release. Im very eager to play with this functionality.
Re: PGraphics Offscreen P3D context and zbuffer
Reply #11 - Jul 11th, 2007, 1:05am
 
Hum, should this bug still exist? I can't get filled or textured offscreen polygons myself, but same code works well for onscreen stuff.

Cheers!
Re: PGraphics Offscreen P3D context and zbuffer
Reply #12 - Jul 11th, 2007, 3:54am
 
Ive seen no full releases of processing since this bug was filed, I've kind of given up on seeing these sorts of bugs fixed. Sad
Re: PGraphics Offscreen P3D context and zbuffer
Reply #13 - Jul 11th, 2007, 4:41pm
 
vade wrote on Jul 11th, 2007, 3:54am:
Ive seen no full releases of processing since this bug was filed, I've kind of given up on seeing these sorts of bugs fixed. Sad


Bit sad. Is there a workaround for this I would want to try offscreen image warping by using texture mapped polygons.
Re: PGraphics Offscreen P3D context and zbuffer
Reply #14 - Jul 16th, 2007, 8:34pm
 
This is still unfixed in 0125.

crappity smack. Seriously?
Pages: 1 2