ManimCommunity / ManimCommunity/manim
opengl not respecting z_index order when rendering
- Dominant language
- Python
- Stars
- 40.9k
- Forks
- 3.1k
- Avg merge
- 3d 12h
- Merged PRs (30d)
- 25
Description
## Description of bug / unexpected behavior
When rendering with opengl, mobjects are layered based on the order that they were added rather than the intended z_index order.
## Expected behavior
Objects should be ordered according to their z_index
## How to reproduce the issue
Run the below code with rendering from either either Cairo or openGL. Cairo gives you the red rectangle while openGL gives you the blue rectangle.
Code for reproducing the problem
```py
config.background_color = WHITE
class MakeRectangles(Scene):
def construct(self):
rect1 = Rectangle(fill_color=BLUE, fill_opacity=1)
rect2 = Rectangle(fill_color=RED, fill_opacity=1)
rect2.z_index = 2
rect1.z_index = 1
self.add(rect2)
self.add(rect1)
```
## Additional media files
Images/GIFs
openGL output

Cairo output

## System specifications
System Details
```
Python 3.12.3
Manim Community v0.18.1
```
LaTeX details
## Additional comments
This seems to be a problem with the render function here:
https://github.com/ManimCommunity/manim/blob/dbad8a86bc6041af78d5fb7d7a07f76d9b164072/manim/scene/scene.py#L440C1-L449C14
Contributor guide
Research direction
Start by running the provided Python reproduction with both Cairo and OpenGL rendering. Then inspect the render function in manim/scene/scene.py at the linked lines and trace how object ordering differs between the renderers. Done means the OpenGL output follows z_index ordering and matches the expected red rectangle result.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- computer-graphics
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100