Skip to main content

OpenGL Portals

My attempt at recreating the portals from the Portal series developed by Valve Software.

Screenshot

Features

  • Ability to look through portals
  • Seemless teleportation
  • Ability to place portals on targeted surfaces
  • Correct collisions with surfaces holding portals
  • Ability to move objects through portals
  • Conservation of velocity when going through portals (partial support)
  • Transition from horizontal to vertical portals and vice-versa (partial support)

Technical aspects

This demo was created entirely in C++ using the OpenGL graphics API. To achieve the portal effect, the scene is rendered from each portal's perspective to a frame buffer object (FBO) which is then displayed on the portal surface. A custom GLSL shader is used to render the portal's border and project the FBO onto the surface correctly.

To make the effect work, linear algebra is used to compute the appropriate transformation for each portal camera. The core idea is to use matrix multiplications and inversions to apply the transformation separating the player's camera from the portal to the corresponding portal's camera, relative to that portal.

Physics are implemented with a custom built AABB solver, with motion calculated using the Euler method.

Scenes are loaded from a custom binary format. I modeled them in Blender and used a Python script to save them in this format.

Animation showcasing the portal effect in motion Animation showcasing a cube being thrown through a portal