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

时间:2013-03-27 11:09:39

标签: python opengl x11 pyopengl

我从另一个帖子中复制了这个代码,它运行正常。

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)

现在我想从X Pixmap生成一个OpenGL纹理。因此,我使用pix = GLX.glXCreatePixmap()而不是w = GLX.glXCreateWindow()。

然后我写了

GLX.glXBindTexImageEXT(d, pix, GLX.GLX_FRONT_EXT, None)

我收到一个错误:ctypes.ArgumentError:argument1 ::预期的LP_struct__XDisplay实例而不是LP_struct__XDisplay

glXBindTexImageEXT()函数在我的_GLX_NV.py中定义(我有一张NVidia卡)。我认为问题来自于_GLX.py和_GLX_NV.py

中struct__XDisplay的双重定义

如果我改变d:

display = _GLX_NV.glXGetCurrentDisplayEXT()

我有一个BadMatch,X_GLXVendorPrivate

你有什么想法,我如何解决我的问题并在Python中将X11 Pixmap转移到OpenGL纹理?

0 个答案:

没有答案