我有一个基本的OpenGL方形绘图代码,我想用另一个线程使用Python。这是正常的代码,运行良好,
from OpenGL.GLUT import *
from OpenGL.GL import *
from OpenGL.GLU import *
class Drawer:
def drawQuad(self, x,y,width):
halfW=width/2
glBegin(GL_QUADS)
glVertex3f(x-halfW, y-halfW, 0)
glVertex3f(x-halfW, y+halfW, 0)
glVertex3f(x+halfW, y+halfW, 0)
glVertex3f(x+halfW, y-halfW, 0)
glEnd()
def display(self):
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
glColor3f(0, 0, 1)
self.drawQuad(0.0,0.0,0.6)
glutSwapBuffers( )
class Visualizer:
drawer = Drawer()
def __init__(self):
glutInit(sys.argv)
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
glutInitWindowSize(250, 250)
glutInitWindowPosition(100, 100)
glutCreateWindow(sys.argv[0])
glutDisplayFunc( self.drawer.display )
glClearColor ( 0, 0, 0, 0 )
glShadeModel( GL_SMOOTH )
glutMainLoop()
visualizer = Visualizer()
这在我的机器上完美无缺。现在,我想把它放在一个线程上。我做了以下,
class Thread(threading.Thread):
visualizer = None
def run(self):
self.visualizer = Visualizer()
thread = Thread()
thread.start()
当我运行线程而不是可视化器本身时,它不起作用。 OpenGL窗口不会出现。我看不出有什么问题。
我尝试了threading
和其他一些例子,他们似乎运作良好。我有点困惑。我的threading
OpenGL方法有什么问题?