Thread: [PyOpenGL-Users] No valid context
Brought to you by:
mcfletch
From: physkets <phy...@tu...> - 2020-04-19 14:20:21
|
Hi! I'm trying to use pyGLFW to make a simple coloured quad, but I fail with the following error message: Traceback (most recent call last): File "first.py", line 121, in <module> gl.glVertexAttribPointer(LOCATION, 2, gl.GL_FLOAT, False, STRIDE, OFFSET) File "/usr/lib/python3.8/site-packages/OpenGL/latebind.py", line 63, in __call__ return self.wrapperFunction( self.baseFunction, *args, **named ) File "/usr/lib/python3.8/site-packages/OpenGL/GL/VERSION/GL_2_0.py", line 469, in glVertexAttribPointer contextdata.setValue( key, array ) File "/usr/lib/python3.8/site-packages/OpenGL/contextdata.py", line 58, in setValue context = getContext( context ) File "/usr/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 I am attaching the program that gives me that error along with the shaders. Am I doing something wrong? This is information from glxinfo: OpenGL vendor string: Intel OpenGL renderer string: Mesa Intel(R) HD Graphics 620 (KBL GT2) OpenGL core profile version string: 4.6 (Core Profile) Mesa 20.0.4 OpenGL core profile shading language version string: 4.60 OpenGL core profile context flags: (none) OpenGL core profile profile mask: core profile OpenGL core profile extensions: OpenGL version string: 4.6 (Compatibility Profile) Mesa 20.0.4 OpenGL shading language version string: 4.60 OpenGL context flags: (none) OpenGL profile mask: compatibility profile OpenGL extensions: OpenGL ES profile version string: OpenGL ES 3.2 Mesa 20.0.4 OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.20 OpenGL ES profile extensions: Also, I'm on a Wayland-based compositor, and am using GLFW compiled for wayland. Might that be an issue? |
From: Ian M. <ia...@ge...> - 2020-04-21 23:38:44
|
On Sun, Apr 19, 2020 at 8:20 AM physkets via PyOpenGL-Users < pyo...@li...> wrote: > Hi! > > I'm trying to use pyGLFW to make a simple coloured quad, but I fail with > the following error message: > > Traceback (most recent call last): File "first.py", line 121, in > <module> gl.glVertexAttribPointer(LOCATION, 2, gl.GL_FLOAT, False, > STRIDE, OFFSET) File > "/usr/lib/python3.8/site-packages/OpenGL/latebind.py", line 63, in > __call__ return self.wrapperFunction( self.baseFunction, *args, **named > ) File "/usr/lib/python3.8/site-packages/OpenGL/GL/VERSION/GL_2_0.py", > line 469, in glVertexAttribPointer contextdata.setValue( key, array ) > File "/usr/lib/python3.8/site-packages/OpenGL/contextdata.py", line 58, in > setValue context = getContext( context ) File > "/usr/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 > I am attaching the program that gives me that error along with the shaders. > > Am I doing something wrong? > FWIW I can't reproduce the issue here, although I note that line 121 mentioned in the traceback does not correspond to that line in the attached code, so I don't know if the difference matters. Anyway, the code works as I would expect (Win x64 Py3.7.3, PyOpenGL 3.1.5). Offhand, I am surprised that `glVertexAttribPointer(...)` would be the call to fail; there are plenty of other GL calls that should have failed beforehand, if indeed they didn't fail. GLFW creates a context, and it looks like you're setting it as current. If that code does what it looks like, correctly, then the error especially wouldn't make sense. I would suggest to try validating the context, perhaps creating a debug context. What happens if you just try drawing an empty window without the problematic setup code? Also, why did you comment the context creation hints? Ian |
From: physkets <phy...@tu...> - 2020-04-22 05:26:51
|
> FWIW I can't reproduce the issue here, although I note that line 121 mentioned in the traceback does not correspond to that line in the attached code, so I don't know if the difference matters. > Sorry about that, I added those commented hint lines later, but used the error output from before. Buy it still gives me the same issue. > > Offhand, I am surprised that `glVertexAttribPointer(...)` would be the call to fail; there are plenty of other GL calls that should have failed beforehand, if indeed they didn't fail. GLFW creates a context, and it looks like you're setting it as current. If that code does what it looks like, correctly, then the error especially wouldn't make sense. I would suggest to try validating the context, perhaps creating a debug context. > Can you point me to some resources that explain how I can do that? > What happens if you just try drawing an empty window without the problematic setup code? > It works if I simply set a single colour using `glClearColor()`. There is no crash, and it displays a window with the right color. > Also, why did you comment the context creation hints? > I did not think those ones were important. I assume it will use that latest version of opengl that I have. Is that not true? |
From: Ian M. <ia...@ge...> - 2020-04-22 07:28:22
|
On Tue, Apr 21, 2020 at 11:26 PM physkets <phy...@tu...> wrote: > Offhand, I am surprised that `glVertexAttribPointer(...)` would be the >> call to fail; there are plenty of other GL calls that should have failed >> beforehand, if indeed they didn't fail. GLFW creates a context, and it >> looks like you're setting it as current. If that code does what it looks >> like, correctly, then the error especially wouldn't make sense. I would >> suggest to try validating the context, perhaps creating a debug context. >> > Can you point me to some resources that explain how I can do that? > In general, Google is your friend on this, but I'll give a shoutout to the OpenGL Wiki. PyOpenGL conveniently does user-level OpenGL error checking (`glGetError()`, etc.) for you, but this is separate from a debug context per-se, which is a driver-level flag that enables additional validation within the context itself. I don't know how this works in Python, since if I need to do robust/fast/reliable graphics, I do it in C++, but in that language it's as easy as: void __stdcall callback_err_gl(GLenum source,GLenum type,GLuint id, GLenum severity,GLsizei length,GLchar const* message,void const* user_param) { //[Notice errors here . . .] } int main(int argc, char* argv[]) { //[...] glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_TRUE); glDebugMessageCallback(callback_err_gl,nullptr); //[...] return 0; } This should be a reasonable guide as you search for the Python binding's equivalent. > What happens if you just try drawing an empty window without the >> problematic setup code? >> > It works if I simply set a single colour using `glClearColor()`. There is > no crash, and it displays a window with the right color. > This suggests to me that the OpenGL context is working, and that there's some peculiarity with the `glVertexAttribPointer(...)` function itself. I have no idea what that might be, though. It working for me on a different platform, and other GL calls succeeding suggests a possible bug. Also, why did you comment the context creation hints? >> > I did not think those ones were important. I assume it will use that > latest version of opengl that I have. Is that not true? > I don't know whether it's mandated to be a particular way by the OpenGL specification (I don't think it is, and the spec. is version-specific anyway), but my experience has been that when you request a context, you'll get back whatever the driver wants to give you. This is often the highest OpenGL version your hardware supports (which is not necessarily a good thing, mind), but it's sometimes not. The point is, you want to *know* what you're getting. Specifying the parameters is a good way to do that. You might also try seeing if you can reproduce the problem in RenderDoc <https://renderdoc.org/>? (Although IDK how well it plays with Python . . .) Ian |
From: physkets <phy...@tu...> - 2020-04-22 08:29:55
|
Thanks for the pointers, I will take a look. One other thing that's bothering me is: > File "/usr/lib/python3.8/site-packages/OpenGL/GL/VERSION/GL_2_0.py", line 469, in glVertexAttribPointer> contextdata.setValue( key, array ) Why does pyOpenGL use the file for version 2? This is what gets used even when I set the context version hints for pyGLFW. Any idea? |
From: physkets <phy...@tu...> - 2020-04-22 17:43:46
|
Okay, so with a lot of help from Florian Rhiem of pyGLFW, I was able to figure out that the issue was because of the wrong 'platform' being chosen. Wayland requires that the EGL platform be used, while the GLX platform was being used. So using the environment variable: `PYOPENGL_PLATFORM=egl` fixed this problem. To see the full discussion that lead to this, refer to: https://github.com/FlorianRhiem/pyGLFW/issues/49 I also found someone else who had a issue due to the same reason, and was equally stumped due to the error not pointing them in the right direction: https://stackoverflow.com/questions/42185728/why-is-glgenvertexarrays-undefined-in-pyopengl-when-using-gtkglarea Can the appropriate platform be used by detecting the environment appropriately? Possibly from the 'XDG_SESSION_TYPE' environment variable obtainable from `os.environ`? |