pygame-community / pygame-ce

🐍🎮 pygame - Community Edition is a FOSS Python library for multimedia applications (like games). Built on top of the excellent SDL library.
https://pyga.me
926 stars 154 forks source link

glcube.py OpenGL.error.Error: Attempt to retrieve context when no valid context (3110) #1575

Closed GalacticEmperor1 closed 5 months ago

GalacticEmperor1 commented 1 year ago

Issue №3110 opened by brccabral at 2022-04-01 18:47:34

Hi, I am getting this error trying to run examples/glcube.py. Any ideas?

Ubuntu 20.04 pygame 2.1.2 (SDL 2.0.16, Python 3.8.10)

python glcube.py          
pygame 2.1.2 (SDL 2.0.16, Python 3.8.10)
Hello from the pygame community. https://www.pygame.org/contribute.html

Traceback (most recent call last):
  File "glcube.py", line 591, in <module>
    main()
  File "glcube.py", line 544, in main
    gpu, f_indices, o_indices = init_gl_modern(display_size)
  File "glcube.py", line 409, in init_gl_modern
    GL.glVertexAttribPointer(loc, 3, GL.GL_FLOAT, False, stride, offset)
  File "/media/Data/PythonProjects/Games/.venv/lib/python3.8/site-packages/OpenGL/latebind.py", line 63, in __call__
    return self.wrapperFunction( self.baseFunction, *args, **named )
  File "/media/Data/PythonProjects/Games/.venv/lib/python3.8/site-packages/OpenGL/GL/VERSION/GL_2_0.py", line 469, in glVertexAttribPointer
    contextdata.setValue( key, array )
  File "/media/Data/PythonProjects/Games/.venv/lib/python3.8/site-packages/OpenGL/contextdata.py", line 58, in setValue
    context = getContext( context )
  File "/media/Data/PythonProjects/Games/.venv/lib/python3.8/site-packages/OpenGL/contextdata.py", line 40, in getContext
    raise error.Error(
OpenGL.error.Error: Attempt to retrieve context when no valid context

Comments

*MyreMylar commented at 2022-04-02 07:30:24*

Anything else odd about your setup? Are you running pygame remotely, in a container on a separate thread? Apparently this error crops up when GL can't access the main thread/display.

The example runs on main right now on windows:

image

This is pygame 2.1.3.dev5 (SDL 2.0.20, Python 3.9.0)


*SiddhantRanade commented at 2022-04-13 02:26:31*

I'm facing the exact same issue when running pygame on Ubuntu 20.04 (WSL2 fresh install) within WSL2 on Windows 11. I verified that glxgears works.


*brccabral commented at 2022-04-13 21:30:44*

Hi @MyreMylar , it is the same problem as # 3114 , on Wayland I get the error, on Xorg it runs OK.


*thisistejaspandey commented at 2022-06-15 02:27:55*

Same issue! Please escalate!!!!


*anji993 commented at 2022-06-30 10:25:14*

I'm facing the exact same issue when running pygame on Ubuntu 20.04 (WSL2 fresh install) within WSL2 on Windows 11. I verified that glxgears works.

Hi @SiddhantRanade have you solved this problem? I meet the same problem as yours!

MyreMylar commented 5 months ago

I wonder if all these reports were related to GL setup on WSL2 ?

See: https://stackoverflow.com/questions/66497147/cant-run-opengl-on-wsl2

I've tested and I can definitely run the glcube example on linux on my raspberry pi - though the Pi only supports up to openGL 3.1 from what I've read so you need to set the USE_MODERN_GL flag in the example to false. 20240530_10h36m41s_grim

MyreMylar commented 5 months ago

OK, I've spent some time getting WLSL setup on my PC with Ubuntu 20.04.

There have been lots of developments since this was originally posted making the whole process a lot easier. I didn't have to export anything or even use VcxSrv

There is now a native XServer included with WLSL since January of this year. This works, but there are clearly still some bugs being worked out as you see a lot of segmentation faults even when running basic diagnostic utilities like:

sudo glxinfo -B

...and when exiting pygame gl apps. I found lots of issue reports to Microsoft about this already so there wasn't much for me to add.

However, despite those it still works reasonably well for what is a pretty niche pygame use case

I also noticed that with the x11 driver you need to set the glcube example to:

USE_MODERN_GL = False

...then it works fine.

x11 driver: image

But with the wayland video driver enabled you can have your modern GL and eat it too:

# add this near the top, before pygame.init()
os.environ['SDL_VIDEODRIVER'] = 'wayland'

...

USE_MODERN_GL = True

Wayland driver:

image

Anyway, overall this is still a bit of a pain to get setup, but most of that is setting up WLSL for python and openGL not really anything to do with pygame-ce. I don't think there was ever anything for us to do here, it is just WLSL slowly improving their compatibility.