t pyOpenGL不会

2024-04-25 18:24:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在看过Youtube上的教程后,用pygame和pyopengl制作一个3d旋转立方体,但是我一直得到一个错误。我用我的终端安装了opengl。在

这是密码

from OpenGL.GL import *
from OpenGL.GLU import *
import pygame


sharps=(
    (1,1,-1),
    (-1,1,-1),
    (-1,-1,-1),
    (1,-1,-1),
    (1,1,1),
    (-1,1,1),
    (-1,-1,1),
    (1,-1,1)
    )
lines=(
    (0,1),
    (1,2),
    (2,3),
    (3,0),
    (0,4),
    (4,5),
    (5,6),
    (6,7),
    (7,4),
    (5,1),
    (6,2),
    (7,3)
    )

def cube():
    glBegin(GL_LINES)
    for x in lines:
        for y in x:
            glVertex3fv(sharps[y])
    glEnd()



def main():
    pygame.init()
    x=800
    y=600
    window=pygame.display.set_mode((x,y), DOUBLEBUF|OPENGL)
    gluPerspective(45,(x/y),0.1,50.0)
    glTranslatef(0.0,0.0,-5)
    glRotatef(0,0,0,0)

    true = True
    while true:
     for i in pygame.event.get():
        if i.type==pygame.QUIT:
            true=False

     glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
     cube()
     pygame.display.flip()
     pygame.time.wait(10)

try:
    main()
except Exception, e:
    print e 

错误呢

global name 'DOUBLEBUF' is not defined

我好像不明白问题出在哪里,我的意思是这对那个家伙有用youtube。拜托帮助


Tags: infromimporttrueformaindef错误