我遵循一个教程,有相同的代码运行该教程,并下载了相同的软件包等,但我得到一个错误,但他没有。如果能帮助解释以下代码中的错误,我们将不胜感激。我应该补充一点,我在这里看到了类似的线索,但到目前为止还没有解决办法。作为参考,它返回错误。
Fatal Python error: (pygame parachute) Segmentation Fault
Current thread 0x00000ba4 (most recent call first):
File "C:/Users/00101010/PycharmProjects/3DPygame/textcompare.py", line 44 in main
File "C:/Users/00101010/PycharmProjects/3DPygame/textcompare.py", line 63 in <module>
Process finished with exit code 3下面是密码。
import pygame
from pygame import *
from OpenGL.GL import *
from OpenGL.GLU import *
import sys
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 Cube():
glBegin(GL_LINES)
for edge in edges:
for vertex in edge:
glVertex3fv(vertices[vertex])
glEnd()
def main():
pygame.init()
displaysize = (800, 600)
pygame.display.set_mode(displaysize, DOUBLEBUF | OPENGL)
gluPerspective(45, (displaysize[0] / displaysize[1]), 0.1, 50.0)
glTranslatef(0.0, 0.0, -5)
while True:
for i in pygame.event.get():
if i.type == pygame.QUIT:
pygame.quit()
sys.exit()
glRotatef(1, 3, 1, 1)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
Cube()
pygame.display.flip()
pygame.time.wait(10)
main()编辑:
sys.version的输出为3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 18:41:36) [MSC v.1900 64 bit (AMD64)]。
运行只使用PyOpenGL的示例将导致init (脚本中的第76行)第35行出现此错误:
OpenGL.error.GLError: GLError( err = 1282, description = b'invalid operation', baseOperation = glViewport, cArguments = (0, 0, 1366, 768) )这一错误还继续存在:
freeglut (C:/Users/OOIOIOIO/PycharmProjects/OpenGLstuff/OpenGLtest.py): fgInitGL2: fghGenBuffers is NULL这是一个相当古老的东芝卫星c660笔记本电脑从2010年前后与英特尔奔腾CPU P6100,它没有一个专门的显卡。
发布于 2017-04-23 01:36:21
致命Python错误:(游戏降落伞)分割故障 pygame.display.set_mode()正在失败。
这听起来很奇怪,因为pygame.display.set_mode()不应该那样失败。如果不支持指定的显示模式,那么pygame就会退却,使用其他的东西。但永远不要像那样直接失败。
好处是,如果您的显示模式不可用,游戏将模仿您所要求的显示模式。 - http://www.pygame.org/docs/tut/DisplayModes.html
因此,由于您正在处理分段错误,这听起来就像是在处理一些不受支持的、可能是旧的、过时的东西。
我已经重写了您的代码,使其只使用PyOpenGL。你能证实你是否能够在不涉及游戏的情况下运行它吗?
import sys
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT 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 init(width, height):
glViewport(0, 0, width, height)
glClearColor(0.0, 0.0, 0.0, 1.0)
glMatrixMode(GL_PROJECTION)
gluPerspective(45.0, (width / height), 0.1, 50.0)
glMatrixMode(GL_MODELVIEW)
glTranslatef(0.0, 0.0, -5.0)
def display():
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glRotatef(1.0, 3.0, 1.0, 1.0)
glBegin(GL_LINES)
for edge in edges:
for vertex in edge:
glVertex3fv(vertices[vertex])
glEnd()
glutSwapBuffers()
def resize(width, height):
glViewport(0, 0, width, height)
if __name__ == "__main__":
glutInit(sys.argv)
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH)
glutInitWindowSize(640, 480)
glutInitWindowPosition(200, 200)
glutCreateWindow(b"OpenGL")
glutDisplayFunc(display)
glutIdleFunc(display)
glutReshapeFunc(resize)
init(glutGet(GLUT_SCREEN_WIDTH), glutGet(GLUT_SCREEN_HEIGHT))
glutMainLoop()请注意,如果您收到类似于以下内容的错误:
OpenGL.error.NullFunctionError:尝试调用未定义的函数glutInit,在调用之前检查bool(glutInit)
那是因为你没有过剩或者更新的自由式 (你可以在这里下载预编译的二进制文件)。
请注意,由于sys.version返回3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 18:41:36) [MSC v.1900 64 bit (AMD64)],所以比遗憾更安全,并下载http://www.transmissionzero.co.uk/software/freeglut-devel/。由于您使用的是64位,所以请确保采用64位版本的freeglut.dll ( zip包含这两个版本)。将freeglut.dll放在Python旁边的项目目录中。
它返回此错误,init中的第35行,模块中的第76行。 OpenGL.error.GLError: GLError( err = 1282,description =b‘无效操作’,baseOperation = glViewport,cArguments = (0,0,1366,768) ) 这个错误也会继续。 freeglut (C:/Users/OOIOIOIO/PycharmProjects/OpenGLstuff/OpenGLtest.py):fgInitGL2: fghGenBuffers为空
不应该发生这种事。听起来不太可能显卡不支持任何形式的OpenGL。然而,考虑到它在glViewport() (它从1.0起就一直是核心)方面有问题。听起来可能是这样的。试着运行OpenGL扩展查看器,看看它是怎么说的。
英特尔奔腾CPU P6100
看起来您的CPU根本不支持OpenGL。这个规范根本没有提到OpenGL。与之相反,这个英特尔核心i7-7Y75 (作为一个随机的例子)。
https://stackoverflow.com/questions/43566412
复制相似问题