【发布时间】:2018-06-29 06:13:50
【问题描述】:
我有这个代码:
import pygame
from pygame.locals import *
from OpenGL.GL 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))
surfaces = (
(0,1,2,3),
(3,2,7,6),
(6,7,5,4),
(4,5,1,0),
(1,5,7,2),
(4,0,3,6)
)
def Cube():
glBegin(GL_QUADS)
for surface in surfaces:
x = 0
for vertex in surface:
x+=1
glColor3fv(colors[x])
glVertex3fv(verticies[vertex])
glEnd()
glBegin(GL_LINES)
for edge in edges:
for vertex in edge:
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)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
glRotatef(1, 3, 1, 1)
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
Cube()
pygame.display.flip()
pygame.time.wait(10)
if __name__ == "__main__":
main()
这个错误:
X Error of failed request: BadValue (integer parameter out of range for operation) Major opcode of failed request: 154 (GLX) Minor opcode of failed request: 3 (X_GLXCreateContext) Value in failed request: 0x0 Serial number of failed request: 25 Current serial number in output stream: 26
我觉得这三行有问题,其实是第三行,显示模式:
pygame.init()
display = (800,600)
pygame.display.set_mode(display, DOUBLEBUF|OPENGL)
只有在 main 函数中的这部分代码,我有同样的问题。如果我在 main 函数中注释第三行,我当然会得到错误:
Traceback(最近一次调用最后一次): 文件“cube_0.py”,第 66 行,在 主要的() 文件“cube_0.py”,第 60 行,在 main pygame.display.flip() pygame.error: 未设置显示模式
【问题讨论】:
-
请发布完整的堆栈跟踪。它有更多有用的信息。
-
请将
colors列表/元组添加到您的示例中并修正拼写错误(verticies应为vertices)。我实际上已经用我自己的颜色列表运行了代码,它对我来说可以正常工作。 -
如果您在 while 循环中注释掉
Cube(),代码会运行吗?考虑到上下文创建本身存在错误(X_GLXCreateContext),似乎一些驱动程序错误比代码中的任何内容都多。顺便说一下,我进行了@skrx 建议的编辑后,它在我的笔记本电脑上运行良好。包括它在什么平台、显卡和驱动程序上运行可能会有所帮助。 -
在主函数中,如果我注释除前三行之外的所有行,这是我得到错误的行:
pygame.display.set_mode(display, DOUBLEBUF|OPENGL) -
你是如何运行这段代码的?你安装了哪些驱动程序?当我尝试在远程机器上使用 openGL 渲染并连接到 ssh 时,我遇到了类似的错误。请参阅此安装驱动程序:--no-opengl-files gist.github.com/wangruohui/df039f0dc434d6486f5d4d098aa52d07
标签: python python-3.x pygame pyopengl