我正在关注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安装吗?
答案 0 :(得分:0)
切换到Python 3.5后,它的工作方式就像Charm。