Reputation: 81
I have this code:
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()
and this error:
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
I think these three lines have problem, actually line three, display mode:
pygame.init()
display = (800,600)
pygame.display.set_mode(display, DOUBLEBUF|OPENGL)
Only with this part of code in main function, I have the same problem. If I comment third line in main function I get, of course, error:
Traceback (most recent call last): File "cube_0.py", line 66, in main() File "cube_0.py", line 60, in main pygame.display.flip() pygame.error: Display mode not set
Upvotes: 2
Views: 4170
Reputation: 708
On Ubuntu 20.04 (uses bash), pygame.init()
was giving me the above X Error.
Putting the following in my ~/.bashrc
solved it for me:
export SDL_VIDEODRIVER='dummy'
Note, also that my $DISPLAY
environment variable is :0
One may thus also need the following in ~/.bashrc
.
export DISPLAY=:0
I was also running code from Pycharm, which required me to start pycharm.sh
from a terminal session that already had the above environment variables initialized (it's a bug in Pycharm 2021).
Upvotes: 2
Reputation: 210877
See Pygame OpenGL init causes an X Error. The issue has nothing to do with your code. It is causes by your system or graphics driver. Possibly you have to update pygame.
Upvotes: 1