Author Topic: Using an object to render to the stencil buffer  (Read 715 times)

Offline rhadamanthus

  • byte
  • *
  • Posts: 5
    • View Profile
Using an object to render to the stencil buffer
« 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
« Last Edit: May 05, 2013, 08:53:26 am by rhadamanthus »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Using an object to render to the stencil buffer
« Reply #1 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) and render the rest.

Offline rhadamanthus

  • byte
  • *
  • Posts: 5
    • View Profile
Re: Using an object to render to the stencil buffer
« Reply #2 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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Using an object to render to the stencil buffer
« Reply #3 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.