gpt4 book ai didi

opengl - PyOpenGL headless (headless)渲染

转载 作者:行者123 更新时间:2023-12-02 08:38:37 25 4
gpt4 key购买 nike

我使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com