我正在努力使用pygame
和pyopengl
初始化OpenGL显示。
import pygame
pygame.init()
pygame.display.set_mode((1920, 1080), pygame.OPENGL)
给出错误:
pygame.error: Couldn't find matching GLX visual
如果我不指定pygame.OPENGL
,则会得到正确初始化的显示和一个pygame窗口。
Python 3.6.2 :: Anaconda custom (64-bit)
)i3
Windows Manager的Manjaro Linux上optirun
来使用Nvidia硬件,但是无论使用哪种图形适配器,我都能获得相同的效果< / li>
glxgears
和optirun glxgears
都可以正常工作,因此我相信OpenGL在机器上可用并且可以正常工作optirun glxinfo
https://pastebin.com/v6VjZgBZ 为了找到合适的显示参数集,我跑了:
import pygame
from pygame.locals import *
pygame.init()
print(pygame.display.Info())
print(pygame.display.list_modes(32, pygame.FULLSCREEN))
print(pygame.display.mode_ok((1920, 1080)))
print(pygame.display.mode_ok((1920, 1080), pygame.OPENGL))
给出了以下输出:
VideoInfo(hw = 0, wm = 1,video_mem = 0
blit_hw = 0, blit_hw_CC = 0, blit_hw_A = 0,
blit_sw = 0, blit_sw_CC = 0, blit_sw_A = 0,
bitsize = 32, bytesize = 4,
masks = (16711680, 65280, 255, 0),
shifts = (16, 8, 0, 0),
losses = (0, 0, 0, 8),
current_w = 3200, current_h = 1800
[(3200, 1800), (2880, 1620), (2560, 1600), (2560, 1440), (2048, 1536), (2048, 1152), (1920, 1440), (1920, 1200), (1920, 1080), (1856, 1392), (1792, 1344), (1680, 1050), (1600, 1200), (1600, 900), (1400, 1050), (1400, 900), (1368, 768), (1280, 1024), (1280, 960), (1280, 800), (1280, 720), (1024, 768), (1024, 576), (960, 540), (864, 486), (800, 600), (720, 405), (640, 480), (640, 360)]
32
32
下面是optirun glxinfo
的摘要,即Nvidia适配器的glxinfo
,显示了几个GLX视觉效果(完整输出https://pastebin.com/v6VjZgBZ):
70 GLX Visuals
visual x bf lv rg d st colorbuffer sr ax dp st accumbuffer ms cav
id dep cl sp sz l ci b ro r g b a F gb bf th cl r g b a ns b eat
----------------------------------------------------------------------------
0x020 24 tc 0 32 0 r y . 8 8 8 8 . . 0 24 8 0 0 0 0 0 0 None
0x021 24 dc 0 32 0 r y . 8 8 8 8 . . 0 24 8 0 0 0 0 0 0 None
0x0ce 24 tc 0 32 0 r y . 8 8 8 8 . . 0 0 0 0 0 0 0 0 0 None
0x0cf 24 tc 0 32 0 r . . 8 8 8 8 . . 0 0 0 0 0 0 0 0 0 None
0x0d0 24 tc 0 32 0 r . . 8 8 8 8 . . 0 24 8 0 0 0 0 0 0 None
0x0d1 24 tc 0 24 0 r y . 8 8 8 0 . . 0 0 0 0 0 0 0 0 0 None
0x0d2 24 tc 0 24 0 r . . 8 8 8 0 . . 0 0 0 0 0 0 0 0 0 None
0x0d3 24 tc 0 24 0 r y . 8 8 8 0 . . 0 24 8 0 0 0 0 0 0 None
0x0d4 24 tc 0 24 0 r . . 8 8 8 0 . . 0 24 8 0 0 0 0 0 0 None
0x0d5 24 tc 0 32 0 r y . 8 8 8 8 . . 0 0 0 0 0 0 0 0 0 None
0x0d6 24 tc 0 32 0 r . . 8 8 8 8 . . 0 0 0 0 0 0 0 0 0 None
0x0d7 24 tc 0 32 0 r y . 8 8 8 8 . . 0 24 8 0 0 0 0 0 0 None
0x0d8 24 tc 0 32 0 r . . 8 8 8 8 . . 0 24 8 0 0 0 0 0 0 None
0x0d9 24 tc 0 32 0 r y . 8 8 8 8 . . 0 24 8 0 0 0 0 0 0 None
0x0da 24 tc 0 32 0 r y . 8 8 8 8 . . 0 24 8 16 16 16 16 0 0 None
0x0db 24 tc 0 24 0 r y . 8 8 8 0 . . 0 24 8 0 0 0 0 0 0 None
0x0dc 24 tc 0 24 0 r y . 8 8 8 0 . . 0 24 8 16 16 16 0 0 0 None
0x0dd 24 tc 0 32 0 r y . 8 8 8 8 . . 0 24 8 0 0 0 0 0 0 None
0x0de 24 tc 0 32 0 r y . 8 8 8 8 . . 0 24 8 16 16 16 16 0 0 None
0x0df 24 tc 0 32 0 r y . 8 8 8 8 . . 0 0 0 0 0 0 0 0 0 None
0x0e0 24 tc 0 32 0 r y . 8 8 8 8 . . 0 0 0 0 0 0 0 0 0 None
0x0e1 24 tc 0 32 0 r y . 8 8 8 8 . . 0 24 8 0 0 0 0 0 0 None
0x0e2 24 tc 0 32 0 r y . 8 8 8 8 . . 0 24 8 0 0 0 0 0 0 None
0x0e3 24 tc 0 24 0 r y . 8 8 8 0 . . 0 0 0 0 0 0 0 0 0 None
0x0e4 24 tc 0 24 0 r y . 8 8 8 0 . . 0 0 0 0 0 0 0 0 0 None
0x0e5 24 tc 0 24 0 r y . 8 8 8 0 . . 0 24 8 0 0 0 0 0 0 None
0x0e6 24 tc 0 24 0 r y . 8 8 8 0 . . 0 24 8 0 0 0 0 0 0 None
0x0e7 24 tc 0 32 0 r y . 8 8 8 8 . . 0 0 0 0 0 0 0 0 0 None
0x0e8 24 tc 0 32 0 r y . 8 8 8 8 . . 0 0 0 0 0 0 0 0 0 None
0x0e9 24 tc 0 32 0 r y . 8 8 8 8 . . 0 24 8 0 0 0 0 0 0 None
0x0ea 24 tc 0 32 0 r y . 8 8 8 8 . . 0 24 8 0 0 0 0 0 0 None
0x0eb 24 dc 0 32 0 r y . 8 8 8 8 . . 0 0 0 0 0 0 0 0 0 None
0x0ec 24 dc 0 32 0 r . . 8 8 8 8 . . 0 0 0 0 0 0 0 0 0 None
0x0ed 24 dc 0 32 0 r . . 8 8 8 8 . . 0 24 8 0 0 0 0 0 0 None
0x0ee 24 dc 0 24 0 r y . 8 8 8 0 . . 0 0 0 0 0 0 0 0 0 None
0x0ef 24 dc 0 24 0 r . . 8 8 8 0 . . 0 0 0 0 0 0 0 0 0 None
0x0f0 24 dc 0 24 0 r y . 8 8 8 0 . . 0 24 8 0 0 0 0 0 0 None
0x0f1 24 dc 0 24 0 r . . 8 8 8 0 . . 0 24 8 0 0 0 0 0 0 None
0x0f2 24 dc 0 32 0 r y . 8 8 8 8 . . 0 0 0 0 0 0 0 0 0 None
0x0f3 24 dc 0 32 0 r . . 8 8 8 8 . . 0 0 0 0 0 0 0 0 0 None
0x0f4 24 dc 0 32 0 r y . 8 8 8 8 . . 0 24 8 0 0 0 0 0 0 None
0x0f5 24 dc 0 32 0 r . . 8 8 8 8 . . 0 24 8 0 0 0 0 0 0 None
0x0f6 24 dc 0 32 0 r y . 8 8 8 8 . . 0 24 8 0 0 0 0 0 0 None
0x0f7 24 dc 0 32 0 r y . 8 8 8 8 . . 0 24 8 16 16 16 16 0 0 None
0x0f8 24 dc 0 24 0 r y . 8 8 8 0 . . 0 24 8 0 0 0 0 0 0 None
0x0f9 24 dc 0 24 0 r y . 8 8 8 0 . . 0 24 8 16 16 16 0 0 0 None
0x0fa 24 dc 0 32 0 r y . 8 8 8 8 . . 0 24 8 0 0 0 0 0 0 None
0x0fb 24 dc 0 32 0 r y . 8 8 8 8 . . 0 24 8 16 16 16 16 0 0 None
0x0fc 24 dc 0 32 0 r y . 8 8 8 8 . . 0 0 0 0 0 0 0 0 0 None
0x0fd 24 dc 0 32 0 r y . 8 8 8 8 . . 0 0 0 0 0 0 0 0 0 None
0x0fe 24 dc 0 32 0 r y . 8 8 8 8 . . 0 24 8 0 0 0 0 0 0 None
0x0ff 24 dc 0 32 0 r y . 8 8 8 8 . . 0 24 8 0 0 0 0 0 0 None
0x100 24 dc 0 24 0 r y . 8 8 8 0 . . 0 0 0 0 0 0 0 0 0 None
0x101 24 dc 0 24 0 r y . 8 8 8 0 . . 0 0 0 0 0 0 0 0 0 None
0x102 24 dc 0 24 0 r y . 8 8 8 0 . . 0 24 8 0 0 0 0 0 0 None
0x103 24 dc 0 24 0 r y . 8 8 8 0 . . 0 24 8 0 0 0 0 0 0 None
0x104 24 dc 0 32 0 r y . 8 8 8 8 . . 0 0 0 0 0 0 0 0 0 None
0x105 24 dc 0 32 0 r y . 8 8 8 8 . . 0 0 0 0 0 0 0 0 0 None
0x106 24 dc 0 32 0 r y . 8 8 8 8 . . 0 24 8 0 0 0 0 0 0 None
0x107 24 dc 0 32 0 r y . 8 8 8 8 . . 0 24 8 0 0 0 0 0 0 None
0x06f 32 tc 0 32 0 r y . 8 8 8 8 . . 0 24 8 0 0 0 0 0 0 None
0x108 32 tc 0 32 0 r y . 8 8 8 8 . . 0 0 0 0 0 0 0 0 0 None
0x109 32 tc 0 32 0 r . . 8 8 8 8 . . 0 0 0 0 0 0 0 0 0 None
0x10a 32 tc 0 32 0 r . . 8 8 8 8 . . 0 24 8 0 0 0 0 0 0 None
0x10b 32 tc 0 32 0 r y . 8 8 8 8 . . 0 0 0 0 0 0 0 0 0 None
0x10c 32 tc 0 32 0 r . . 8 8 8 8 . . 0 0 0 0 0 0 0 0 0 None
0x10d 32 tc 0 32 0 r y . 8 8 8 8 . . 0 24 8 0 0 0 0 0 0 None
0x10e 32 tc 0 32 0 r . . 8 8 8 8 . . 0 24 8 0 0 0 0 0 0 None
0x10f 32 tc 0 32 0 r y . 8 8 8 8 . . 0 24 8 0 0 0 0 0 0 None
0x110 32 tc 0 32 0 r y . 8 8 8 8 . . 0 24 8 0 0 0 0 0 0 None
请帮助我诊断问题并启动启用OpenGL的pygame窗口。
更新20190131
我按照{hidefromkgb的建议,在ipython
(python 3.6.2)中设置了24位色彩模式,但是遇到了同样的问题(我之前曾尝试过):
In [1]: import pygame
In [2]: pygame.init()
Out[2]: (6, 0)
In [3]: pygame.display.set_mode((1920, 1080), pygame.OPENGL, 24)
---------------------------------------------------------------------------
error Traceback (most recent call last)
<ipython-input-3-b9c85baaf5fe> in <module>()
----> 1 pygame.display.set_mode((1920, 1080), pygame.OPENGL, 24)
error: Couldn't find matching GLX visual
我能够使用GLUT从c ++使OpenGL正常工作。
更新#2 20190131
我现在有两个最小的程序(python
,c++
),带有附带的strace输出(请参见https://paste.ee/p/ah1nq)。
此python
程序失败,并出现 GLX Visuals 错误:
import pygame
pygame.init()
pygame.display.set_mode((1920, 1080), pygame.OPENGL)
此c++
程序成功创建了一个窗口:
#include <GL/glut.h>
void display(void) {
}
int
main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutCreateWindow("window initialisation test");
return 0;
}
c++
程序是用g++ test.cpp -lGL -lglut -o test
编译的。
我查看了strace
的输出,但无法做出正面或反面的结果。
更新#3 20190131
我在上述两个程序上运行ltrace
并得到
python
$ ltrace python test.py
__libc_start_main(0x400ab0, 2, 0x7ffe171cfb58, 0x400cc0 <unfinished ...>
_PyMem_SetupAllocators(0x400da8, 0x7ffe171cfb58, 0x7ffe171cfb70, 0x7f82b2fd4578) = 0
PyMem_RawMalloc(24, 0x400daf, 0x7ffe171cfb70, 6) = 0xf8d260
PyMem_RawMalloc(24, 0xf8d270, 0xf8d260, 0xf8d260) = 0xf8d280
setlocale(LC_ALL, nil) = "C"
_PyMem_RawStrdup(0x7f82b2f9c007, 0, 0, 0xf8d280) = 0xf8d2a0
setlocale(LC_ALL, "") = "LC_CTYPE=en_AU.utf8;LC_NUMERIC=e"...
Py_DecodeLocale(0x7ffe171d1310, 0, 0, 0) = 0xf90710
Py_DecodeLocale(0x7ffe171d1317, 0, 0xf90728, 0) = 0xf90740
setlocale(LC_ALL, "C") = "C"
PyMem_RawFree(0xf8d2a0, 16, 0, 0) = 0
Py_Main(2, 0xf8d260, 0, 0xf8e260Traceback (most recent call last):
File "test.py", line 4, in <module>
pygame.display.set_mode((1920, 1080), pygame.OPENGL)
pygame.error: Couldn't find matching GLX visual
) = 1
_PyMem_SetupAllocators(0x400da8, 0x7f82b2fd6710, 0, 2880) = 0
PyMem_RawFree(0xf90710, 0x400daf, 0, 6) = 0
PyMem_RawFree(0xf90740, 0xf90760, 0, 0xf90760) = 0
PyMem_RawFree(0xf8d260, 0xf90700, 0, 0xf90700) = 0
PyMem_RawFree(0xf8d280, 0xf8f310, 0, 0xf8f310) = 0
+++ exited (status 1) +++
c++
$ ltrace ./test
glutInit(0x7ffd507caccc, 0x7ffd507cadb8, 0x7ffd507cadb8, 128) = 0
glutInitDisplayMode(18, 1, 0x7fb32b5c44e0, 32) = 0x7fb32b7d70e0
glutCreateWindow(0x562359efe004, 1, 0x7fb32b5c44e0, 32) = 1
--- SIGWINCH (Window changed) ---
+++ exited (status 0) +++
更新#4 20190213
感谢您输入@hidefromkgb。
我尝试使用pygame.OPENGL | pygame.DOUBLEBUF
并仅通过18
,但是得到了相同的结果。
import pygame
from pygame.locals import *
pygame.init()
pygame.display.set_mode((1920, 1080), pygame.OPENGL | pygame.DOUBLEBUF)
---------------------------------------------------------------------------
error Traceback (most recent call last)
<ipython-input-11-59807ce30659> in <module>()
3
4 pygame.init()
----> 5 pygame.display.set_mode((1920, 1080), pygame.OPENGL | pygame.DOUBLEBUF)
error: Couldn't find matching GLX visual
print(pygame.OPENGL)
print(pygame.DOUBLEBUF)
2
1073741824
答案 0 :(得分:0)
对不起,您回答的太迟了,以前还没有看过您的修改。将来,如果您需要引起他们的注意,请在评论中使用昵称给人们打电话。
ltrace
似乎使问题更加明确。 glutInitDisplayMode
的第一个参数等于18,这意味着GLUT_DOUBLE | GLUT_DEPTH
,对于GLUT_DOUBLE
= 2,GLUT_DEPTH
= 16。
在GL初始化期间,pygame.display.set_mode
调用又缺少这两个标志。
尝试使用pygame.OPENGL | pygame.DOUBLEBUF
而不是pygame.OPENGL
。