Manim 有两套渲染后端:Cairo 逐帧画到 CPU 上再编码,OpenGL 走显卡实时绘制。它们不是新旧关系,而是两种用途。这段代码把各自的能力与限制并排对照。

完整代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from manim import *
class RendererChoiceDemo(Scene):
"""--renderer cairo / opengl:两种渲染后端的分工"""
def construct(self):
title = Text("--renderer 选哪个:cairo 还是 opengl", font_size=31).to_edge(UP, buff=0.4)
self.play(Write(title))
def panel(name, flag, rows, color):
head = Text(name, font_size=25, color=color)
sub = Text(flag, font="Consolas", font_size=19, color=GREY_B)
body = VGroup(*[Text(r, font_size=19, color=WHITE) for r in rows])
body.arrange(DOWN, buff=0.14, aligned_edge=LEFT)
inner = VGroup(head, sub, body).arrange(DOWN, buff=0.18, aligned_edge=LEFT)
box = RoundedRectangle(corner_radius=0.12, width=5.7,
height=inner.height + 0.7,
stroke_color=color, stroke_width=2,
fill_color=color, fill_opacity=0.08)
inner.move_to(box.get_center())
return VGroup(box, inner)
left = panel("cairo(默认)", "--renderer cairo",
["CPU 逐帧渲染,稳定性最好", "支持全部 Manim 特性",
"输出 mp4 / png,适合成片", "缺点:不能实时预览"], BLUE_B)
right = panel("opengl", "--renderer opengl",
["GPU 实时绘制,可开交互窗口", "拖动视角、边看边调",
"适合 3D 场景与调试", "缺点:部分特性尚未支持"], GREEN_B)
cards = VGroup(left, right).arrange(RIGHT, buff=0.6).next_to(title, DOWN, buff=0.55)
self.play(FadeIn(left, shift=RIGHT * 0.3), run_time=0.9)
self.play(FadeIn(right, shift=LEFT * 0.3), run_time=0.9)
self.wait(0.5)
# 同一段代码,两种后端
code = Text("manim -qm demo.py MyScene --renderer opengl",
font="Consolas", font_size=20, color=GREEN)
code.next_to(cards, DOWN, buff=0.55)
self.play(FadeIn(code, shift=UP * 0.2))
knob = Text("成片用 cairo,调 3D 用 opengl", font_size=21, color=YELLOW)
knob.next_to(code, DOWN, buff=0.35)
self.play(FadeIn(knob, shift=UP * 0.15))
self.wait(1.6)

演示视频

下载 Python 脚本

要点

  • --renderer cairo 是默认值,CPU 逐帧渲染,特性支持最全,交付视频统一用它
  • --renderer opengl 走 GPU,可开交互窗口实时拖动视角,调 3D 场景效率高得多
  • OpenGL 后端仍有部分特性未实现,正式出片前切回 cairo 复跑一遍确认结果一致

代码来源:Manim Community 官方文档 Guides / Configuration 与 CLI 参考(MIT),示例代码按 Manim CE 0.20.1 编写并实跑验证。