www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: rhadamanthus on May 05, 2013, 02:33:01 am

Title: Using an object to render to the stencil buffer
Post by: rhadamanthus on May 05, 2013, 02:33:01 am
Hello,
I am developing an augmented reality application. I successfully aligned a 3D box with an actual box that I see through the camera. The next thing I want to do is to use the 3D box to hide other 3D objects around it, so it would appear as if the other 3D objects were behind the real box in the image. (They should be occluded by the real box if they are behind it)

I think this can be done using the stencil buffer, however, I am not experienced enough to deduct what I need to do, neither in OpenGL nor in JPCT. Anybody has any hints about that?
I saw that IRenderHook can be used to inject code into the rendering pipeline, but I'm not exactly sure how this works or how to set different stencil modes. Is it that every time repeatRendering() returns true, the method afterRendering() is called?

Any help would be appreciated. thank you
Title: Re: Using an object to render to the stencil buffer
Post by: EgonOlsen on May 06, 2013, 04:16:56 pm
This should be possible without stencil buffers. Try to render the cube only, do http://www.jpct.net/jpct-ae/doc/com/threed/jpct/FrameBuffer.html#clearColorBufferOnly(com.threed.jpct.RGBColor) (http://www.jpct.net/jpct-ae/doc/com/threed/jpct/FrameBuffer.html#clearColorBufferOnly(com.threed.jpct.RGBColor)) and render the rest.
Title: Re: Using an object to render to the stencil buffer
Post by: rhadamanthus on May 06, 2013, 09:13:42 pm
Yup! That's exactly what I ended up doing. Thank you for the reply.
 I put the box in a separate world instance in order to render them independently. Is that how it is supposed to be used?
Title: Re: Using an object to render to the stencil buffer
Post by: EgonOlsen on May 06, 2013, 09:23:14 pm
I put the box in a separate world instance in order to render them independently. Is that how it is supposed to be used?
Yes, that's just fine.