ManimCommunity / manim

A community-maintained Python framework for creating mathematical animations.
https://www.manim.community
MIT License
26.81k stars 1.84k forks source link

Transparent background with Opengl #3919

Open Implosiv3 opened 3 months ago

Implosiv3 commented 3 months ago

Description of bug / unexpected behavior

When you try to export a video with the --transparent flag and the opengl renderer, the output video doesn't have any alpha channel.

Expected behavior

Rendered video should have transparency (alpha channel).

How to reproduce the issue

Use a ThreeDScene or Scene (the problem is the renderer, not the scene) with some OpenGLRectangle (or OpenGLMobject you want), set the self.camera.background_opacity = 0 and use the --renderer opengl and the -t tags/flags.

Additional comments

If you check the opengl_renderer.py file, that is the specific renderer that takes part when you send that flag, you can see in the line 596 that the background color is forced to have 1.0 as alpha background. This means that the background will never be transparent. That alpha value should check if the flag --transparent is set as True, as the cairo_renderer.py does, or at least allow you changing that value.

Even in the update_frame method of that file, if you manually force the background_color to be (0, 0, 0, 0) as a numpy array, it is set as 1.0 for the alpha as the setter is forcing it.