python - 运行 pyOpenGL 时出现 NameError

标签 python python-3.x windows-8.1 nameerror pyopengl

我对设置环境以使用 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

如果您认为更多信息会有所帮助,请直接询问。 谢谢

最佳答案

改变

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()              

虽然没有那么紧凑,但它可以帮助我弄清楚谁在做什么。

关于python - 运行 pyOpenGL 时出现 NameError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23319925/

相关文章:

python - UTF8 Python Material list

python - 字典 Python 中 If-Condition 上的 KeyError

c# - 处理带有视频的 MediaElement

windows-store-apps - Windows 应用商店应用提交的 IndexedDB 问题

python - 捕获由 Factory 分配的 Python 属性引发的异常

python - 如何从 Python 程序连接到 Db2 Event Store 数据库?

python - 如何在 Python 反汇编程序中访问堆栈的内容?

python - Pandas read_sql() 可以返回哪些异常

for-loop - Gnuplot 5.0补丁lvl1在WIN 8.1上崩溃

python - "Insufficient Permission: Request had insufficient authentication scopes"即使是最通用的范围