Skip to content

Conversation

@d-orm
Copy link
Contributor

@d-orm d-orm commented Jul 11, 2025

Fix the issues raised in #369

  1. use ProgrammablePipelineRenderer

    • Tested with the internal example as well as pyopengl/moderngl/zengl examples, and this appears to work fine. Using FixedPipelineRenderer (after fixing the import path) did not work (raises OSError: exception: access violation reading 0x0000000000000090), but swapping to ProgrammablePipelineRenderer I do not see any issues.

    • This also "works" out of the box with ZenGL, but raises an exception when zengl pipelines are created dynamically during run-time, so we'll still need the custom zengl-imgui renderer (which is fine and why that lib was originally created).

  2. fix tab/space key maps

    • Tab was being ignored so added this to key_map
    • Space was not being allowed to register as printable, so removed this from key_map
  3. update resize refresh meth

    • refresh_font_texture method no longer exists, calling _update_textures from the base renderer behaves as expected.

Let me know if you'd like any further testing or changes. I wonder if we could/should move the pygame_backend up a level out of the "disabled" backends folder as this appears to me to work well, + remove the comment note at the top of the file?

fix tab/space key maps
update resize refresh meth
@pthom
Copy link
Owner

pthom commented Jul 14, 2025

Hi,

Many thanks for this PR!

  1. use ProgrammablePipelineRenderer

perfect!

I wonder if we could/should move the pygame_backend up a level out of the "disabled" backends folder as this appears to me to work well, + remove the comment note at the top of the file?

Yes, please move it a level up.

Also, please move the file "example_python_backend_pygame.py" to the examples/ folder.

This also "works" out of the box with ZenGL, but raises an exception when zengl pipelines are created dynamically during run-time, so we'll still need the custom zengl-imgui renderer (which is fine and why that lib was originally created).

I would be interested in having an example with zengl somewhere inside examples (I did add previously an example with wgpu, in example_python_backend_wgpu.py).


At the moment, I have an error when running "bindings/imgui_bundle/python_backends/examples_disabled/example_python_backend_pygame.py": glGetUniformLocation is not available with the default settings of OpenGL on macOS (OpenGL2 is used).

See message below

pygame 2.6.1 (SDL 2.28.4, Python 3.12.0)
Hello from the pygame community. https://www.pygame.org/contribute.html
2025-07-14 15:36:45.830 Python[30564:35016120] ApplePersistenceIgnoreState: Existing state will not be touched. New state will be written to /var/folders/w1/w77kvvl9613022ksfxj7v8xh0000gn/T/org.python.python.savedState
Traceback (most recent call last):
  File "/Users/pascal/dvp/OpenSource/ImGuiWork/_Bundle/imgui_bundle/bindings/imgui_bundle/python_backends/examples_disabled/example_python_backend_pygame.py", line 101, in <module>
    main()
  File "/Users/pascal/dvp/OpenSource/ImGuiWork/_Bundle/imgui_bundle/bindings/imgui_bundle/python_backends/examples_disabled/example_python_backend_pygame.py", line 40, in main
    impl = PygameRenderer()
           ^^^^^^^^^^^^^^^^
  File "/Users/pascal/dvp/OpenSource/ImGuiWork/_Bundle/imgui_bundle/bindings/imgui_bundle/python_backends/python_backends_disabled/pygame_backend.py", line 25, in __init__
    super(PygameRenderer, self).__init__()
  File "/Users/pascal/dvp/OpenSource/ImGuiWork/_Bundle/imgui_bundle/bindings/imgui_bundle/python_backends/opengl_backend_programmable.py", line 62, in __init__
    super(ProgrammablePipelineRenderer, self).__init__()
  File "/Users/pascal/dvp/OpenSource/ImGuiWork/_Bundle/imgui_bundle/bindings/imgui_bundle/python_backends/opengl_base_backend.py", line 20, in __init__
    self._create_device_objects()
  File "/Users/pascal/dvp/OpenSource/ImGuiWork/_Bundle/imgui_bundle/bindings/imgui_bundle/python_backends/opengl_backend_programmable.py", line 90, in _create_device_objects
    self._attrib_location_tex = gl.glGetUniformLocation(
                                ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/pascal/dvp/OpenSource/ImGuiWork/_Bundle/imgui_bundle/v312_2/lib/python3.12/site-packages/OpenGL/latebind.py", line 63, in __call__
    return self.wrapperFunction( self.baseFunction, *args, **named )
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/pascal/dvp/OpenSource/ImGuiWork/_Bundle/imgui_bundle/v312_2/lib/python3.12/site-packages/OpenGL/GL/VERSION/GL_2_0.py", line 430, in glGetUniformLocation
    return baseOperation( program, name )
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/pascal/dvp/OpenSource/ImGuiWork/_Bundle/imgui_bundle/v312_2/lib/python3.12/site-packages/OpenGL/platform/baseplatform.py", line 415, in __call__
    return self( *args, **named )
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/pascal/dvp/OpenSource/ImGuiWork/_Bundle/imgui_bundle/v312_2/lib/python3.12/site-packages/OpenGL/error.py", line 230, in glCheckError
    raise self._errorClass(
OpenGL.error.GLError: GLError(
	err = 1282,
	description = b'invalid operation',
	baseOperation = glGetUniformLocation,
	cArguments = (1, b'Texture\x00'),
	result = -1
)

This issue can easily be solved by adding these settings in the example:

    # --- request an OpenGL 3.3 core (forward-compatible) context ---
    pygame.display.gl_set_attribute(pygame.GL_CONTEXT_MAJOR_VERSION, 3)
    pygame.display.gl_set_attribute(pygame.GL_CONTEXT_MINOR_VERSION, 3)
    pygame.display.gl_set_attribute(
        pygame.GL_CONTEXT_PROFILE_MASK, pygame.GL_CONTEXT_PROFILE_CORE
    )
    # macOS needs the forward-compatible flag too
    pygame.display.gl_set_attribute(pygame.GL_CONTEXT_FORWARD_COMPATIBLE_FLAG, 1)

    # existing code below
    pygame.display.set_mode(size, pygame.DOUBLEBUF | pygame.OPENGL | pygame.RESIZABLE)

@d-orm
Copy link
Contributor Author

d-orm commented Jul 14, 2025

Yes, please move it a level up.
Also, please move the file "example_python_backend_pygame.py" to the examples/ folder.

Will do!

I would be interested in having an example with zengl somewhere inside examples (I did add previously an example with wgpu, in example_python_backend_wgpu.py).

Sure thing, once we merge this PR and do a release for zengl-imgui, I'll follow up with a PR here for a zengl example.

At the moment, I have an error when running "bindings/imgui_bundle/python_backends/examples_disabled/example_python_backend_pygame.py": glGetUniformLocation is not available with the default settings of OpenGL on macOS (OpenGL2 is used).

Ah of course I forgot about that macOS quirk. I'll add those pygame.display.gl_set_attribute lines to the example on this PR too. (it runs fine for me on Windows too with those added, so no need for conditional or anything)

Will get these updates pushed this evening/tomorrow.

Thanks!

add macos compat flags to example
@d-orm
Copy link
Contributor Author

d-orm commented Jul 14, 2025

@pthom done :)

@pthom pthom merged commit 29762c3 into pthom:main Jul 15, 2025
@pthom
Copy link
Owner

pthom commented Jul 15, 2025

I just merged the PR with some small adjustments

Thanks!

@d-orm
Copy link
Contributor Author

d-orm commented Jul 15, 2025

Awesome, ah yes sorry I forgot those adjustments, thanks for adding!

No problem very happy to contribute :)

Do you have any ETA on when you might do a release next? (so I can remove the module import monkey patch needed for the zengl-imgui lib)

@pthom
Copy link
Owner

pthom commented Jul 15, 2025

Do you have any ETA on when you might do a release next? (so I can remove the module import monkey patch needed for the zengl-imgui lib)

Probably around september.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants