Name Error: global name 'BaseFunction' is not defined
Name Error: global name 'BaseFunction' is not defined
我正在学习 pygame 教程 (thenewboston),但我在使用 pyOpenGL 时遇到了一些问题。
我在 anaconda-spyder3.3.4
上使用 python 2.7
代码如下:
from OpenGL.GL import *
import pygame
from pygame.locals import *
from OpenGL.GLU import *
vertices = (
(1, -1, -1),
(1, 1, -1),
(-1, 1, -1),
(-1, -1, -1),
(1, -1, 1),
(1, 1, 1),
(-1, -1, 1),
(-1, 1, 1),
)
edges = (
(0,1),
(0,3),
(0,4),
(2,1),
(2,3),
(2,7),
(6,3),
(6,4),
(6,7),
(5,1),
(5,4),
(5,7),
)
def Draw_Cube():
glBegin(GL_LINES) # delimit vertices.
for edge in edges:
for vertex in edge:
glVertex3fv(vertices[vertex])
glEnd()
def main():
pygame.init()
display = (800, 600)
pygame.display.set_mode(display, DOUBLEBUF|OPENGL)
gluPerspective(45.0, display[0]/ display[1], 1, 50.0 )
glTranslatef(0.0,0.0, -5.0)
glRotatef(20, 0, 0, 0)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
Draw_Cube()
pygame.display.update()
pygame.time.wait(10)
main()
我希望得到一个 3D 立方体,但它却显示了这个回溯:
Traceback (most recent call last):
File "<ipython-input-8-72d57f8b0dbe>", line 1, in <module>
glEnd()
File "/home/cadu/anaconda2/lib/python2.7/site-packages/OpenGL /latebind.py", line 61, in __call__
return self.wrapperFunction( self.baseFunction, *args, **named )
File "/home/cadu/anaconda2/lib/python2.7/site-packages/OpenGL/GL/exceptional.py", line 45, in glEnd
return BaseFunction( )
NameError: global name 'BaseFunction' is not defined
所以,我正在尝试搜索文档,但我没有找到任何相关信息。可能是pyOpenGL安装?
切换到 Python 3.5 后,它的工作就像一个魅力。
我正在学习 pygame 教程 (thenewboston),但我在使用 pyOpenGL 时遇到了一些问题。 我在 anaconda-spyder3.3.4
上使用 python 2.7代码如下:
from OpenGL.GL import *
import pygame
from pygame.locals import *
from OpenGL.GLU import *
vertices = (
(1, -1, -1),
(1, 1, -1),
(-1, 1, -1),
(-1, -1, -1),
(1, -1, 1),
(1, 1, 1),
(-1, -1, 1),
(-1, 1, 1),
)
edges = (
(0,1),
(0,3),
(0,4),
(2,1),
(2,3),
(2,7),
(6,3),
(6,4),
(6,7),
(5,1),
(5,4),
(5,7),
)
def Draw_Cube():
glBegin(GL_LINES) # delimit vertices.
for edge in edges:
for vertex in edge:
glVertex3fv(vertices[vertex])
glEnd()
def main():
pygame.init()
display = (800, 600)
pygame.display.set_mode(display, DOUBLEBUF|OPENGL)
gluPerspective(45.0, display[0]/ display[1], 1, 50.0 )
glTranslatef(0.0,0.0, -5.0)
glRotatef(20, 0, 0, 0)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
Draw_Cube()
pygame.display.update()
pygame.time.wait(10)
main()
我希望得到一个 3D 立方体,但它却显示了这个回溯:
Traceback (most recent call last):
File "<ipython-input-8-72d57f8b0dbe>", line 1, in <module>
glEnd()
File "/home/cadu/anaconda2/lib/python2.7/site-packages/OpenGL /latebind.py", line 61, in __call__
return self.wrapperFunction( self.baseFunction, *args, **named )
File "/home/cadu/anaconda2/lib/python2.7/site-packages/OpenGL/GL/exceptional.py", line 45, in glEnd
return BaseFunction( )
NameError: global name 'BaseFunction' is not defined
所以,我正在尝试搜索文档,但我没有找到任何相关信息。可能是pyOpenGL安装?
切换到 Python 3.5 后,它的工作就像一个魅力。