我有兴趣设置一个用pyOpenGL编写粒子模拟器代码的环境。我已经安装了pyOpenGL。 这是测试代码,只是为了确保opengl可以正常工作。
from OpenGL import *
from OpenGL.GLUT import *
from OpenGL.GLU import *
window = 0
width, height = 500,400
def draw():
glClear(GL_COLOR_BUFFER_BIT |GL_DEPTH_BUFFER_BIT)
glLoadIdentity()
glutDwapBuffers()
#initialization
glutInit()
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH)
glutInitWindowSize(width,height)
glutInitWindowPosition(0,0)
window = glutCreateWindow(b"noobtute")
glutDisplayFunc(draw)
glutIdleFunc(draw)
glutMainLoop()
但是,当我从命令运行脚本时,我收到以下错误:
NameError: name 'glClear' is not defined
GLUT Display callback <function draw at 0x0000000002F8CB70> with (),{} failed:
returning None name 'glClear' is not defined
我尝试重新安装pyOpengl但没有成功。
我在Windows 8.1上运行Python 3.4
如果您认为更多信息会有所帮助,请询问。 感谢
答案 0 :(得分:4)
更改
from OpenGL import *
到
from OpenGL.GL import *
但是,我赞成使用这种格式:
import OpenGL.GL as GL
import OpenGL.GLU as GLU
import OpenGL.GLUT as GLUT
window = 0
width, height = 500,400
def draw():
GL.glClear(GL.GL_COLOR_BUFFER_BIT |GL.GL_DEPTH_BUFFER_BIT)
GL.glLoadIdentity()
GLUT.glutSwapBuffers()
#initialization
GLUT.glutInit()
GLUT.glutInitDisplayMode(GLUT.GLUT_RGBA | GLUT.GLUT_DOUBLE | GLUT.GLUT_ALPHA |
GLUT.GLUT_DEPTH)
GLUT.glutInitWindowSize(width,height)
GLUT.glutInitWindowPosition(0,0)
window = GLUT.glutCreateWindow(b"noobtute")
GLUT.glutDisplayFunc(draw)
GLUT.glutIdleFunc(draw)
GLUT.glutMainLoop()
虽然不那么紧凑,但它可以帮助我保持正确的做法。