Skip to content

OpenGL & Python under Linux + pyopengl : Attempt to retrieve context when no valid context #321

@giorgosg

Description

@giorgosg

Hello. Thanks for making this project.

I have been trying to use immapp with pyopengl and I get an error. I found this error also happens when running the demo_custom_background.py example. I've tried setting the open_gl_options through code or with a hello_imgui.ini file but it doesn't help.

$ python bindings/imgui_bundle/demos_python/demos_immapp/demo_custom_background.py 
Traceback (most recent call last):
  File "/home/f/Projects/imgui_bundle/bindings/imgui_bundle/demos_python/demos_immapp/demo_custom_background.py", line 610, in <module>
    sys.exit(main())
             ~~~~^^
  File "/home/f/Projects/imgui_bundle/bindings/imgui_bundle/demos_python/demos_immapp/demo_custom_background.py", line 604, in main
    immapp.run(runner_params, add_ons_params)
    ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/f/.local/lib/python3.13/site-packages/imgui_bundle/_patch_runners_add_save_screenshot_param.py", line 38, in patched_run
    run_backup(*args, **kwargs)
    ~~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "/home/f/Projects/imgui_bundle/bindings/imgui_bundle/demos_python/demos_immapp/demo_custom_background.py", line 593, in <lambda>
    runner_params.callbacks.post_init = lambda: app_state.init_app_resources_3d(VERTEX_SHADER_SOURCE, FRAGMENT_SHADER_SOURCE)
                                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/f/Projects/imgui_bundle/bindings/imgui_bundle/demos_python/demos_immapp/demo_custom_background.py", line 490, in init_app_resources_3d
    self.full_screen_quad_vao = create_full_screen_quad_vao()
                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/home/f/Projects/imgui_bundle/bindings/imgui_bundle/demos_python/demos_immapp/demo_custom_background.py", line 185, in create_full_screen_quad_vao
    GL.glVertexAttribPointer(0, 2, GL.GL_FLOAT, GL.GL_FALSE, 4 * 4, ctypes.c_void_p(0))
    ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "src/latebind.pyx", line 52, in OpenGL_accelerate.latebind.Curry.__call__
  File "/home/f/.local/lib/python3.13/site-packages/OpenGL/GL/VERSION/GL_2_0.py", line 465, in glVertexAttribPointer
    contextdata.setValue( key, array )
    ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
  File "/home/f/.local/lib/python3.13/site-packages/OpenGL/contextdata.py", line 58, in setValue
    context = getContext( context )
  File "/home/f/.local/lib/python3.13/site-packages/OpenGL/contextdata.py", line 40, in getContext
    raise error.Error(
        """Attempt to retrieve context when no valid context"""
    )
OpenGL.error.Error: Attempt to retrieve context when no valid context

it looks like pyopengl tries to use opengl 2.0?

$ glxinfo | grep "OpenGL version"
OpenGL version string: 4.6 (Compatibility Profile) Mesa 24.3.4

i am on linux and have also tried building the bundle from the latest source.

Metadata

Metadata

Assignees

No one assigned

    Labels

    faqA frequent issue, remaining opened to facilitate discoverability

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions