opengl - PyOpenGL headless (headless)渲染

标签 opengl glfw headless pyopengl

我使用 PyOpenGL+glfw 进行渲染。

当尝试在 headless (headless)机器(例如服务器)上执行相同操作时,glfw.init() 失败:

glfw.GLFWError: (65544) b'X11: The DISPLAY environment variable is missing'
Fatal Python error: Couldn't create autoTLSkey mapping
Aborted (core dumped)

我找到了一些有关 headless (headless)渲染的信息,但仅限于直接使用OpenGL而不是通过python时

编辑:我知道也许 glfw 无法支持它。没有 glfw 但使用其他东西的解决方案也可能有效......

最佳答案

解决方案是使用 xvfb 作为虚拟帧缓冲区。

问题在于 Ubuntu 中使用 apt-get install libglfw3 libglfw3-dev 安装的 glfw 是旧的且不合适,因此我们需要从源代码编译它。

这是一个完整的工作 docker 示例:

docker run --name headless_test -ti ubuntu /bin/bash

# Inside the ubuntu shell:
apt update && apt install -y python3 python3-pip git python-opengl xvfb xorg-dev cmake
pip3 install pyopengl glfw
mkdir /projects
git clone https://github.com/glfw/glfw.git /projects/glfw
cd /projects/glfw
cmake -DBUILD_SHARED_LIBS=ON .
make
export PYGLFW_LIBRARY=/projects/glfw/src/libglfw.so
xvfb-run python3 some_script_using_pyopengl_and_glfw.py

这是使用它的 PyOpenGL 代码的基础:

from OpenGL.GL import *
from OpenGL.GLU import *
import glfw

glfw.init()
# Set window hint NOT visible
glfw.window_hint(glfw.VISIBLE, False)
# Create a windowed mode window and its OpenGL context
window = glfw.create_window(DISPLAY_WIDTH, DISPLAY_HEIGHT, "hidden window", None, None)
# Make the window's context current
glfw.make_context_current(window)

关于opengl - PyOpenGL headless (headless)渲染,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54483960/

相关文章:

opengl - glBindVertexBuffer 与 glBindBuffer

c++ - 灰度中的 glDrawPixels?

c++ - OpenGL 扭曲纹理

python - 寻找一个使用 GLFW 的简单 OpenGL (3.2+) Python 示例

Jenkins 中的 Android 模拟器

java - 可以在 headless (headless)Linux环境下截图吗?

linux - 如何将 headless (headless)窗口浏览器从远程服务器传输到我的本地计算机?

c++ - 与 OpenGL 中的矩阵堆栈混淆?

qt - 在 Qt 中启动 2D 游戏

c++ - OpenGL 漫射照明问题