ManimCommunity / ManimCommunity/manim

opengl not respecting z_index order when rendering

Open
#4,070 1 comment 0 reactions 0 assignees View on GitHub
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
![Why_ManimCE_v0 18 1](https://github.com/user-attachments/assets/dc73e4c0-770f-42fe-8c8d-6931d075591a)
Cairo output
![Why_ManimCE_v0 18 1](https://github.com/user-attachments/assets/6447414a-bcb3-4df2-90de-de225e849171)

## 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

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.