名称错误:未定义全局名称“BaseFunction”

问题描述 投票:0回答:1

我正在关注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-2.7 pygame spyder pyopengl
1个回答
0
投票

切换到Python 3.5后,它就像魅力一样。

© www.soinside.com 2019 - 2024. All rights reserved.