X请求失败的错误:BadValue(整数参数超出操作范围),PyOpenGL

时间:2018-01-19 22:50:18

标签: python python-3.x pygame pyopengl

我有这段代码:

auth.uid

并出现此错误:

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

只有主函数中的这部分代码,我才有同样的问题。如果我在main函数中评论第三行,我当然会得到错误:

  

追踪(最近一次通话):     文件" cube_0.py",第66行,in       主要()     文件" cube_0.py",第60行,在main中       pygame.display.flip()   pygame.error:未设置显示模式

1 个答案:

答案 0 :(得分:0)

Pygame OpenGL init causes an X Error。该问题与您的代码无关。这是由您的系统或图形驱动程序引起的。可能你必须更新 pygame。