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 › Depth sorting at will
Page Index Toggle Pages: 1
Depth sorting at will (Read 1046 times)
Depth sorting at will
Jul 8th, 2007, 8:04pm
 
Hey all,

Anybody got a clue how to mix 3D and 2D and still be in control? I can't figure out how to turn on and off depth sorting per frame. Simplified, what I want to do is this:

Code:

// let processing take care of polygon sorting
hint(ENABLE_DEPTH_SORT);

//clear screen
background(255);
// disable depth checking here
image(bgImg, -bgX, -bgY);
// enable depth checking here
pushMatrix();
// do wicked stuff
...
popMatrix();
// disable depth checking again here
image(onTopImg, guiX, guiY);


The reason why I want to escape perspective is because the images are pretty big and I don't want to have them rescaled for every frame. Also, background(PImage) is also no good because I want to move the images around.

Tried with various hint():s, g.begin/endDraw(), clearing the zbuffer and even fiddeling with camera settings and switching between ortho() and perspective() and of course searching the forums.

Any advice appreciated.

Mkn.

Re: Depth sorting at will
Reply #1 - Jul 9th, 2007, 11:11am
 
im not sure how does processing handles it to you, i do the opengl calls as:


GL opengl;


setup:
 opengl = ((PGraphicsOpenGL)g).gl;


mainloop:
 opengl.glDisable( GL.GL_DEPTH_TEST );
 opengl.glDepthMask( false );

hope that helps,
Re: Depth sorting at will
Reply #2 - Jul 10th, 2007, 9:22pm
 
I think you may be confusing ENABLE_DEPTH_SORT with turning the z-buffer on and off - the depth sorting is only to arrange the draw order of polygons so that alpha blending works right with translucent polygons, and I don't think that is what you're looking for here.  Processing handles draw order on a first come first served basis unless ENABLE_DEPTH_SORT is flagged, using the z-buffer to handle occlusion and all that fun stuff.  As far as turning off the z-buffer checking, I'm not entirely sure, perhaps someone else knows what to do about this.
Re: Depth sorting at will
Reply #3 - Jul 10th, 2007, 10:04pm
 
i think you're looking for hint(DISABLE_DEPTH_TEST).
Re: Depth sorting at will
Reply #4 - Jul 11th, 2007, 2:21pm
 
Hmm, its not what I'm looking for. Smiley

I mean, what I want to move around images in the background in their original size and then display 3d perspective stuff on top and then finally have a final layer or unresized bitmaps on top.

Something like:
Code:

background(255);

ortho();
moveAroundBackgroundBitmaps();

perspective();
clearZBuffer();
moveAround3DObjects();

ortho();
clearZBuffer();
drawGUIonTop();


I guess it could be done with off screen buffers for the 3D rendering, but that would only work in P3D. Also, I'd prefer not having to copy a lot of buffers with alpha channels every frame as the purpose is to preserve computational resourses to where its better needed.

Re: Depth sorting at will
Reply #5 - Jul 11th, 2007, 3:47pm
 
You can clear the zBuffer manually:

P3D:
Code:

for(int i=0;i<((PGraphics3D)g).zbuffer.length;i++)
{
((PGraphics3D)g).zbuffer[i]=Float.MAX_VALUE;
}


OpenGL:
Code:

gl.glClear(GL.GL_DEPTH_BUFFER_BIT);
Re: Depth sorting at will
Reply #6 - Jul 11th, 2007, 4:07pm
 
Ah!

Code:

Arrays.fill( ((PGraphics3D)g).zbuffer, Float.MAX_VALUE);


is probably even more efficient. Smiley

Brilliant. Thanks!
Page Index Toggle Pages: 1