使用PyOpenGl时eglInitialize()出错(err = 12296)

lmyy7pcs  于 2023-08-04  发布在  其他
关注(0)|答案(2)|浏览(318)

我正在尝试使用PyOpenGL和EGL在我的NanoPi M1 Plus上使用Mali400 GPU设置无头渲染。当我运行eglInitalize时,我得到以下错误:
错误代码:

File "ferb_gpu_1.py", line 22, in <module>
    if not eglInitialize( display, major, minor):
  File "/home/fa/berryconda3/lib/python3.6/site-packages/OpenGL/platform/baseplatform.py", line 402, in __call__
    return self( *args, **named )
  File "/home/fa/berryconda3/lib/python3.6/site-packages/OpenGL/error.py", line 232, in glCheckError
    baseOperation = baseOperation,
OpenGL.error.GLError: GLError(
    err = 12296,
    baseOperation = eglInitialize,
    cArguments = (
        <OpenGL._opaque.EGLDisplay_pointer object at 0xb603f800>,
        c_long(0),
        c_long(0),
    ),
    result = 0
)

字符串
下面是我写的代码:

if not os.environ.get( 'PYOPENGL_PLATFORM' ):
    os.environ['PYOPENGL_PLATFORM'] = 'egl'

os.environ['DISPLAY'] = '0.0'

if os.environ.get( 'TEST_NO_ACCELERATE' ):
    OpenGL.USE_ACCELERATE = False

display = eglGetDisplay(EGL_DEFAULT_DISPLAY)
if(display == EGL_NO_DISPLAY):
    print("Failed to get EGL display! Error: %s", eglGetError())
    exit()

major,minor = ctypes.c_long(),ctypes.c_long()
if not eglInitialize( display, major, minor):
    print("Unable to initialize")
    exit()

jvlzgdj9

jvlzgdj91#

问题是,我使用的是os.environ['DISPLAY'] = '0.0',但它应该是os.environ['DISPLAY'] = ':0.0'

g6ll5ycj

g6ll5ycj2#

在使用Nvidia驱动程序的Ubuntu 22.04中,此问题浪费了大量时间。@AdishRao提到的解决方案一开始并不奏效。但后来我更新了Nvidia驱动程序的版本535.54.03和它的工作就像一个魅力。它也适用于os.environ['DISPLAY'] = ':0'。在导入OpenGL或导入它的任何其他模块之前,必须绝对设置环境变量。

import os

# if not os.environ.get("PYOPENGL_PLATFORM"):
os.environ["PYOPENGL_PLATFORM"] = "egl"

os.environ["DISPLAY"] = ":0"
# os.environ["EGL_DEVICE_ID"] = "0"

import OpenGL

字符串

相关问题