我想做一个3d旋转立方体后,在Youtube上看了一个教程,但我一直得到一个错误。我用我的终端安装了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 和错误
未定义全局名称“DOUBLEBUF”
我似乎不明白问题出在哪里,我的意思是,这对youtube.Please帮助的人来说是有效的
发布于 2016-04-18 12:01:47
DOUBLEBUF是在吡咯中定义的,因此您必须编写:
pygame.DOUBLEBUF还可以将导入更改为:
from pygame import *https://stackoverflow.com/questions/36692832
复制相似问题