Repository: ManimCommunity/manim

Issue:
OpenGL renderer does not respect post-add shift() animations for Text
## Description of bug / unexpected behavior
Animated shifts() applied after (text) objects are added to the scene are not respected when using the OpenGL backend.

Cairo:
![image](https://user-images.githubusercontent.com/35181624/130194237-0aa7ca31-0094-4c8c-a007-b754f1ce5221.png)

OpenGL:
![image](https://user-images.githubusercontent.com/35181624/130194205-fe38aba0-b181-4ebb-9353-fc5acd7936e7.png)

## Expected behavior
Cairo:
![image](https://user-images.githubusercontent.com/35181624/130194237-0aa7ca31-0094-4c8c-a007-b754f1ce5221.png)

## How to reproduce the issue
<!-- Provide a piece of code illustrating the undesired behavior. -->

<details><summary>Code for reproducing the problem</summary>

```py
from manim import *

class AcronymAnimation(Scene):
    def construct(self):
        p = Text("P").scale(3)
        i = Text("I").scale(3)
        d = Text("D").scale(3)

        p.next_to(i, LEFT)
        d.next_to(i, RIGHT)

        self.add(p, i, d)
        
        self.play(p.animate.set_color(YELLOW))
        self.play(p.animate.shift(UP * 2 + LEFT * 3))

        prop = Text("roportional").next_to(p, RIGHT)

        self.play(Create(prop))
```

</details>


## Additional media files
<!-- Paste in the files manim produced on rendering the code above. -->

<details><summary>Images/GIFs</summary>

<!-- PASTE MEDIA HERE -->

</details>


## Logs
<details><summary>Terminal output</summary>
<!-- Add "-v DEBUG" when calling manim to generate more detailed logs -->

```
PASTE HERE OR PROVIDE LINK TO https://pastebin.com/ OR SIMILAR
```

<!-- Insert screenshots here (only when absolutely necessary, we prefer copy/pasted output!) -->

</details>


## System specifications

<details><summary>System Details</summary>

- OS (with version, e.g Windows 10 v2004 or macOS 10.15 (Catalina)):
- RAM:
- Python version (`python/py/python3 --version`):
- Installed modules (provide output from `pip list`):
```
PASTE HERE
```
</details>

<details><summary>LaTeX details</summary>

+ LaTeX distribution (e.g. TeX Live 2020):
+ Installed LaTeX packages:
<!-- output of `tlmgr list --only-installed` for TeX Live or a screenshot of the Packages page for MikTeX -->
</details>

<details><summary>FFMPEG</summary>

Output of `ffmpeg -version`:

```
PASTE HERE
```
</details>

## Additional comments
<!-- Add further context that you think might be relevant for this issue here. -->



Discussion:
This has to have something to do with `Text` and how `get_familiy()` and `parents` work I think, since it works if you change `Text("P")` to some other Mobject, say `Star()`. This is all related to `refresh_bounding_box()`.
> This has to have something to do with `Text` and how `get_familiy()` and `parents` work I think, since it works if you change `Text("P")` to some other Mobject, say `Star()`. This is all related to `refresh_bounding_box()`.

What way does it behave differently? I was trying to fix this and you can simply set `self.needs_new_bounding_box = True` in `apply_points_function` or set `works_on_bounding_box` to False to fix it but I am guessing it isn't that simple? 
I think I see what the issue is, the problem is that Text has no points, and animations interpolate only mobjects with points - https://github.com/ManimCommunity/manim/blob/58092a71a9b6d162024fa235dc696e8b9bad3a9d/manim/animation/transform.py#L141

If I change it to `get_family` with or without points it also fixes it, but worried that could cause a problem

If you use the underlying SVGMObject `prop = Text("roportional").next_to(p.get_family()[1], RIGHT)` it works because it has points and is being updated during the animation. As it is part of the logic of the animation it also works if you shift without animating as you won't have the interpolation logic then.

I am not sure of the best solution, maybe for opengl we need to make sure the bounding boxes are updated after animations as we can't rely on the animation updating all bounding boxes?
Thanks for investigating @ryanmccauley211. I think I tried to apply the animation to all submobjects whenever a text mobject was passed. Hence my initial guess. I see you also looked at Issue #1867, I guess that was somewhat similar but seemed to be magically resolved. (I didn't see your ping there, sorry.)

As for the best solution, something like `get_family_members_with_points()` sounds like the way to go? Maybe we should also look how it is done in 3b1b/manim at the moment.
Turns out they just `get_family()`  that I mentioned in the last comment that I tried and it worked https://github.com/3b1b/manim/blob/0fd8fdc3cae2441f3c4a0d038075c380da965583/manimlib/animation/transform.py#L96

Turns out the purposely changed it to get_family() so that's reasuring that maybe safe to do - https://github.com/3b1b/manim/commit/f1c32b64cc7dc1c4756d960938722a0d5a6fc149

Will raise a PR later after testing it
> Turns out they just `get_family()` that I mentioned in the last comment that I tried and it worked https://github.com/3b1b/manim/blob/0fd8fdc3cae2441f3c4a0d038075c380da965583/manimlib/animation/transform.py#L96
> 
> Turns out the purposely changed it to get_family() so that's reasuring that maybe safe to do - [3b1b/manim@f1c32b6](https://github.com/3b1b/manim/commit/f1c32b64cc7dc1c4756d960938722a0d5a6fc149)
> 
> Will raise a PR later after testing it

Great!

Resolving patch:
diff --git a/manim/animation/animation.py b/manim/animation/animation.py
--- a/manim/animation/animation.py
+++ b/manim/animation/animation.py
@@ -1,7 +1,7 @@
 """Animate mobjects."""
 
 
-from .. import logger
+from .. import config, logger
 from ..mobject import mobject, opengl_mobject
 from ..mobject.mobject import Mobject
 from ..mobject.opengl_mobject import OpenGLMobject
@@ -221,6 +221,8 @@ def get_all_mobjects(self) -> Sequence[Mobject]:
         return self.mobject, self.starting_mobject
 
     def get_all_families_zipped(self) -> Iterable[Tuple]:
+        if config["renderer"] == "opengl":
+            return zip(*(mob.get_family() for mob in self.get_all_mobjects()))
         return zip(
             *(mob.family_members_with_points() for mob in self.get_all_mobjects())
         )
diff --git a/manim/animation/transform.py b/manim/animation/transform.py
--- a/manim/animation/transform.py
+++ b/manim/animation/transform.py
@@ -138,6 +138,8 @@ def get_all_families_zipped(self) -> Iterable[tuple]:  # more precise typing?
             self.starting_mobject,
             self.target_copy,
         ]
+        if config["renderer"] == "opengl":
+            return zip(*(mob.get_family() for mob in mobs))
         return zip(*(mob.family_members_with_points() for mob in mobs))
 
     def interpolate_submobject(


Test patch: