python-xlib 유형을 python-opengl과 직접 사용할 수 없습니다. 그러나 같은 창에서 XID는 python-opengl을 사용하는 숫자 일뿐입니다.
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)
# a terrible end to a terrible piece of code...
raw_input()
이것은 정말 끔찍합니다. (오류 검사 및 분명한 fbConfig 분별없는 선택)
실제로 모든 ctypes xlib 호출을 수행 할 수 있어야합니다. 예를 들어, Pyglet은 어떻게 든 관리하지만 특정 문제가 무엇인지 몰랐습니다.
Xlib과 같은 저수준 라이브러리를 사용하는 데는 완벽한 이유가있을 수 있지만 질문해야합니다. [QtOpenGL] (http://srinikom.github.com/pyside)와 같은 훨씬 높은 수준의 것을 사용 해본 적이 있습니까? -docs/PySide/QtOpenGL/index.html)를 PySide에서 구할 수 있습니까? PySide를 사용하여 작성한 코드는 Xlib을 사용하여 작성한 코드와 달리 여러 플랫폼 (Windows, Linux, Mac)에서도 작동합니다. 그냥 생각. – crayzeewulf
아니요, PyOpenGL에는 자체 xlib 구현이 없습니다. 실제로 파이썬 측에있는 것은 없습니다. Python-xlib는 2009 년에 마지막으로 배포되었으므로 실제로 죽었습니다. GLUT 또는 상위 레벨 툴킷 중 하나를 사용하십시오. –
@crayzeewulf : 그래, 나는 좋은 이유가있다. 바탕 화면에 대화식 OpenGL 배경 화면을 그리는 X-windows 해킹을하고 있습니다. 그것은 EMWH 힌트와 몇 가지 지저분한 비트를 설정하는 것을 포함하므로, Qt 또는 무엇이든지 그것을 할 수 있을지는 의문입니다. –