Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix modal window rendering in pyopengl backend (Fix #156) #157

Merged
merged 1 commit into from
Dec 17, 2023

Conversation

Aman-Anas
Copy link
Contributor

To address issue #156 .

@pthom pthom changed the title Fix modal window rendering in pyopengl backend Fix modal window rendering in pyopengl backend (Fix #156) Dec 17, 2023
@pthom
Copy link
Owner

pthom commented Dec 17, 2023

The weird thing is, I tried it like (idx_buffer_offset + command.idx_offset * imgui.INDEX_SIZE) and it seems to break rendering all over the place. The link does mention that some backends try and calculate the offsets manually, which may be what's happening here with idx_buffer_offset being incorrect.

Based on info here ocornut/imgui#4845 apparently the start offsets are no longer simply the sum of the ElemCount's, and that's essentially how idx_buffer_offset is calculated right now. Still need to test, but I think idx_buffer_offset may not be needed. It could also be that since idx_buffer is already initialized to 0 in the ProgrammablePipeline it doesn't affect anything, and maybe the FixedPipeline is different.

I opened a pull request for the version using command.idx_offset * imgui.INDEX_SIZE

This is strange. I would need more info in order to make sure the correction is OK
Could you provide an minimal reproducible example where the issue occurs?

@pthom pthom merged commit 7b36d12 into pthom:main Dec 17, 2023
16 checks passed
@Aman-Anas
Copy link
Contributor Author

Aman-Anas commented Dec 17, 2023

Here's a minimal reproducible example for the modal issue, just modified the example glfw3 backend script a little. The modal window is grayed on the inside before the renderer fix, and grayed on the outside afterwards.

from imgui_bundle.python_backends.glfw_backend import GlfwRenderer
import OpenGL.GL as gl  # type: ignore
from imgui_bundle import imgui
import glfw  # type: ignore
import sys


def main():
    imgui.create_context()
    window = impl_glfw_init()
    impl = GlfwRenderer(window)

    show_custom_window = True

    while not glfw.window_should_close(window):
        glfw.poll_events()
        impl.process_inputs()

        imgui.new_frame()

        if show_custom_window:
            is_expand, show_custom_window = imgui.begin("Custom window", True)
            if is_expand:
                if imgui.button("Open modal"):
                    imgui.open_popup("Test Modal")

                modal_expand, _ = imgui.begin_popup_modal("Test Modal", True)
                if modal_expand:
                    imgui.text("hello there")
                    imgui.text("with the bug, this window is grayed out")
                    imgui.end_popup()

            imgui.end()

        gl.glClearColor(1.0, 1.0, 1.0, 1)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT)

        imgui.render()
        impl.render(imgui.get_draw_data())
        glfw.swap_buffers(window)

    impl.shutdown()
    glfw.terminate()


def impl_glfw_init():
    width, height = 1280, 720
    window_name = "minimal ImGui/GLFW3 example"

    if not glfw.init():
        print("Could not initialize OpenGL context")
        sys.exit(1)

    # OS X supports only forward-compatible core profiles from 3.2
    glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 3)
    glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 3)
    glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE)

    glfw.window_hint(glfw.OPENGL_FORWARD_COMPAT, gl.GL_TRUE)

    # Create a windowed mode window and its OpenGL context
    window = glfw.create_window(
        int(width), int(height), window_name, None, None)
    glfw.make_context_current(window)

    if not window:
        glfw.terminate()
        print("Could not initialize Window")
        sys.exit(1)

    return window


if __name__ == "__main__":
    main()

@pthom
Copy link
Owner

pthom commented Dec 17, 2023

I merged your PR, thanks for the repro

@pthom
Copy link
Owner

pthom commented Dec 17, 2023

And congrats for the fix!

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