Question

I'm trying to realize portals using OpenGL via the stencil buffer. The technique seems simple enough to me: render the portal into the stencil buffer, render the scene as viewed from the virtual camera behind the target portal (restricted to the stencil buffer), render portal into depth buffer, render normal view.

However, when I do it that way, objects between the virtual camera and the target portal will be drawn in front of the portal, resulting in a wrong image (as I only want to draw the objects that can be seen through the portal - the ones "behind" the portal). If I would look onto the portal straight, I could simply use the near clipping plane, but for arbitrary views that does not seem to work.

For a better explanation, here is a drawing of my problem:

Portal problem drawing
(source: 42prozent.de)

Was it helpful?

Solution

Maybe glClipPlane is what you want? Or you could take a look at Oblique Near Plane Clipping, to try to do some funky projection math that modifies your near plane to be that of the portal.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top