如何在Python和NVidia卡上使用Xlib和OpenGL?

2024-06-16 09:59:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我从另一个线程复制了这段代码,它运行得很好。在

from Xlib import X, display
from OpenGL import GL, GLX
from OpenGL.raw._GLX import struct__XDisplay
from ctypes import *

# some python-xlib code...
pd = display.Display()
pw = pd.screen().root.create_window(50, 50, 200, 200, 0,
                                pd.screen().root_depth,
                                X.InputOutput, X.CopyFromParent)
pw.map()

# ensure that the XID is valid on the server
pd.sync()

# get the window XID
xid = pw.__resource__()

# a separate ctypes Display object for OpenGL.GLX
xlib = cdll.LoadLibrary('libX11.so')
xlib.XOpenDisplay.argtypes = [c_char_p]
xlib.XOpenDisplay.restype = POINTER(struct__XDisplay)
d = xlib.XOpenDisplay("")

# use GLX to create an OpenGL context on the same window XID
elements = c_int()
configs = GLX.glXChooseFBConfig(d, 0, None, byref(elements))
w = GLX.glXCreateWindow(d, configs[0], c_ulong(xid), None)
context = GLX.glXCreateNewContext(d, configs[0], GLX.GLX_RGBA_TYPE, None, True)
GLX.glXMakeContextCurrent(d, w, w, context)

# some python-opengl code....
GL.glShadeModel(GL.GL_FLAT)
GL.glClearColor(0.5, 0.5, 0.5, 1.0)

GL.glViewport(0, 0, 200, 200)
GL.glMatrixMode(GL.GL_PROJECTION)
GL.glLoadIdentity()
GL.glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0)

GL.glClear(GL.GL_COLOR_BUFFER_BIT)
GL.glColor3f(1.0, 1.0, 0.0)
GL.glRectf(-0.8, -0.8, 0.8, 0.8)

# assume we got a double buffered fbConfig and show what we drew
GLX.glXSwapBuffers(d, w)

现在我想从xpixmap生成一个OpenGL纹理。所以不是w=GLX.glXCreateWindow(),我使用pix=GLX.glXCreatePixmap(). 在

然后我写了

^{pr2}$

我得到一个错误:ctypes.ArgumentError:argument1::应为LP_struct_uxdisplay实例,而不是LP_struct_uxdisplay

glXBindTexImageEXT()函数在my\u GLX中定义_内华达州(我有一张NVidia卡)。我认为问题来自于struct\uxdisplay的双重定义_GLX.py以及_内华达州在

如果我将d改为:

display = _GLX_NV.glXGetCurrentDisplayEXT()

我有个不好的对手,X\u GLXVendorPrivate

你有什么想法,我如何解决我的问题,并在python中将x11pixmap转换成OpenGL纹理?在


Tags: thefromimportdisplaywindowctypesstructopengl