i'm wondering in which way the Portal Game works. You can stand between one portal and the other, it's so fascinating.
Every time you shoot one portal, maybe, the level is copied throught it? or is only a camera/frustum/viewport effect?
I want to develope it in OpenGL, any suggestion?
This has been a nightmare for them to implement. Play the game through with "director's commentary" and you'll get some interesting interviews mentioning it.
Here's the basic idea. When you look into the blue portal, you're not looking at a copy of the level, but simply at the same thing rendered from a different point of view. The engine renders the part seen through the portal from the point of view "behind" the orange portal, corresponding to your location in front of the blue one. It needs to take special care not to show anything that's in between this virtual viewpoint and the back of the orange portal. The view frustum is adjusted to include only the bits you can see through the blue portal.
But that's not the whole story, because what if you can see one portal through the other? You'll get an "infinite" feedback effect. In practice, the effect is not actually infinite; it just does enough iterations (say 40) until the images get small enough that you can't tell the difference. Each next iteration can be rendered at a smaller size, so we don't have to render the whole level 40 times at full resolution. But there's still work involved with clipping, culling, and so on.
In OpenGL, this could either be accomplished by rendering to a texture using framebuffer objects (FBOs), or rendering directly to the end result but clipped using the stencil buffer (thanks datenwolf!). But, as the paragraphs above show, that's only the beginning of the story. If you're just getting started with OpenGL, I'm afraid you're completely at the wrong end of the difficulty scale.
(Aside: There are also interesting things going on with the physics engine, where an object that's halfway through a portal needs to be in two places at once. Another big headache.)
They keywords are: Stencil buffer, clip planes and recursive rendering.
The stencil buffer is used to cut out the part of the viewport that's "the portal". This is achieved by rendering some helper geometry, when the main view of the scene is rendered.
In the next step the scene is rendered a further time, but this time the scene is moved by an additional transformation, namely the one describing the relative alignment of the portals to each other. Then a clip-plane is placed on the portal plane and the scene is rendered. During this rendering another portal stencil may be rendered, which triggers a further recursion. To prevent infinite loops in a hall of mirrors situation there's a recursion limit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With