我想在程序中多次打开和关闭一个过剩的窗口。我想出了这个python代码:
#!/usr/bin/python
from OpenGL.GLUT import *
from OpenGL.GLU import *
from OpenGL.GL import *
#parameters for viewer
name = 'Viewer'
width, height = 500, 500
spheresize = 0.3
def display():
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
glLoadIdentity()
gluLookAt(0,0,10,0,0,0,0,1,0)
glPushMatrix()
color = [1.0,0.0,0.0,1.0]
glMaterialfv(GL_FRONT,GL_DIFFUSE,color)
glTranslatef(0.0,0.0,1.0)
glutSolidSphere(spheresize,20,20)
glPopMatrix()
glutSwapBuffers()
return
def closing():
glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE,GLUT_ACTION_GLUTMAINLOOP_RETURNS) glutLeaveMainLoop()
return
#---------------BEGIN PROGRAM----------------
while 1:
glutInit()
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
glutInitWindowSize(width,height)
glutCreateWindow(name)
glClearColor(0.,1.0,0.,1.)
glShadeModel(GL_SMOOTH)
glEnable(GL_CULL_FACE)
glEnable(GL_DEPTH_TEST)
glEnable(GL_LIGHTING)
glEnable(GL_LIGHT0)
glMatrixMode(GL_PROJECTION)
gluPerspective(40.,1.,1.,40.)
glMatrixMode(GL_MODELVIEW)
glPushMatrix()
glutDisplayFunc(display)
glutCloseFunc(closing)
glutMainLoop()
print "\n\nMAIN MENUE:"
print "p - print"
print "q - quit"
option = raw_input()
if option == "q":
raise SystemExit
elif option == "p":
print ("Hello World!")
当我尝试运行此窗口时,窗口按照我的意图关闭,但在使用选项' p'之后它会崩溃。同 freeglut错误:函数glutCreateWindow在没有先调用' glutInit'的情况下调用。
在我发现一些关于类似问题的其他帖子后,我认为它可能是我的库链接的问题,所以我试图在另一台计算机上的干净python环境中运行它。它给出了同样的错误。
有没有人知道我的错误是什么?