I'm using OpenGL. I have problem with my engine's portal implementation. To create the first portal I do:
- create a virtual camera with the position of the second portal and the correct orientation
- render whole scene from virtual camera to the texture using FBO
- render the first portal using the texture created before.
The problem: The virtual camera is rendering to the texture with the main projection view, so when I use this texture to render the first portal, everything is rescaled. The virtual camera should only render some part of the view to prevent scaling.
The problem could perhaps be solved by changing the virtual camera's projection matrix, but I don't know how to calculate such a matrix.
Here's how it looks:
This picture shows one portal (the texture is a little bit deformed on bottom and top, but that's not important now) and some other objects. The second portal is behind the camera, and the camera is in the middle between the two portals.
We can clearly see that the portal texture is rescaled down to the portal size. As I said before, I think the virtual camera should have another projection matrix, but how do I calculate it? Or is there a better way?