This is a very simple question, but after a brief search and reading through the "similar questions" I could not yet find an answer.
I'm creating a 2D game using OpenGL and came across a problem: Let's say I wanted to create portals. An Entity can move into a portal A and come out of the corresponding portal B. Transforming the coordinates and velocity of the entity is easy, but this would create "hard" texture-teleportation. Which means: while half of the entity is in the A-portal, it won't be rendered on the corresponding B side. How would I create a smooth transition?
My first Idea was: I define "exit"- and "entry"-zones containing the transformation function (Matrix). Now when an Entity enteres the exit-zone the entity is also drawn at the entry zone using the transformation-matrix relative the the entry/exit-zones. But drawing it twice would still give me the difficulty, that I need to clip the entity on the portals "backside". (The entity shall vanish behind portal A when entering).
So my second thought was, that there should be a solution using (vertex?) shader? But how would such a shader look like? (Example code would be nice, but not neccessary. I'd rather want to have a "what the shader would do" answer). Would I define Uniforms (exit- and entry zones) which the shader would clip/transform ("move") the vertexes from?
How does a typical solution for this clipping look like? Or where could I read some information about these kind of problems? I only found some to 3D versions, where the view of portal B should be rendered in portal A. But this does not solve the object-moving-through-it problem...I think In my opinion changing the draw-order, or rendering something above the backside of the portals is not the right way to go, since this could create strange behavior in certain situations. (Portal B is just behind portal A for example. One of both would be overdrawn I think.)