【发布时间】:2019-02-14 04:48:47
【问题描述】:
我是第一次使用 PyOpenGl,并观看了有关它的 YouTube 教程。这是视频:https://www.youtube.com/watch?v=R4n4NyDG2hI&t=1464s
但是,当我尝试代码时,pygame 打开并移动一帧,然后它会冻结并且不会停止加载。我不确定这是因为我使用的系统还是我使用的 python 版本。
我有一台 11-6 英寸的 2012 MacBook Air,并且正在使用 python 2.7.15。我使用 python 2 而不是 python 3 的原因是因为当我尝试 pip3 安装 PyOpenGl 时,它给了我一个错误。
import pygame
from pygame.locals import *
from OpenGL.GL import *
from OpenGL.GLU import *
verticies = (
(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 Cube():
global edges
glBegin(GL_LINES)
for edges in edges:
for vertex in edges:
glVertex3fv(verticies[vertex])
glEnd()
def main():
pygame.init()
display = (800,600)
pygame.display.set_mode(display, DOUBLEBUF|OPENGL)
gluPerspective(45, (display[0]/display[1]), 0.1, 50.0)
glTranslatef(0.0, 0.0, -5)
glRotatef(20, 3, 1, 1)
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)
Cube()
pygame.display.flip()
pygame.time.wait(10)
main()
发生的另一件事是,当我运行程序时,IDLE 给了我这个错误消息:
Traceback (most recent call last):
File "/Users/SplatM4n/Desktop/First3DGraphics.py", line 73, in <module>
main()
File "/Users/SplatM4n/Desktop/First3DGraphics.py", line 66, in main
Cube()
File "/Users/SplatM4n/Desktop/First3DGraphics.py", line 44, in Cube
for vertex in edges:
TypeError: 'int' object is not iterable
我也觉得这是问题的一部分,所以请提供任何帮助。
谢谢,SplatM4n
【问题讨论】: