pthom / imgui_bundle

Dear ImGui Bundle: an extensive set of Ready-to-use widgets and libraries, based on ImGui. Start your first app in 5 lines of code, or less. Whether you prefer Python or C++, this pack has your back!
https://pthom.github.io/imgui_bundle/
MIT License
592 stars 63 forks source link

Grayed out Modal windows in python backend #156

Closed Aman-Anas closed 6 months ago

Aman-Anas commented 6 months ago

The interior of modal windows is grayed out in the backend, rather than the exterior area. This seems to be a documented issue with some backends with a newer Dear Imgui version

Documented here: https://github.com/ocornut/imgui/releases/tag/v1.86

I was able to fix it by changing some lines in the opengl renderer

                gl.glDrawElements(
                    gl.GL_TRIANGLES,
                    command.elem_count,
                    gltype,
                    ctypes.c_void_p(idx_buffer_offset),
                )

to

                gl.glDrawElements(
                    gl.GL_TRIANGLES,
                    command.elem_count,
                    gltype,
                    ctypes.c_void_p(command.idx_offset * imgui.INDEX_SIZE)
                )

I don't really know opengl too well, but it seems to work fine.

pthom commented 6 months ago

If I read correctly the linked info, the correction should be

   gl.glDrawElements(
                    gl.GL_TRIANGLES,
                    command.elem_count,
                    gltype,
                    ctypes.c_void_p(idx_buffer_offset + command.idx_offset * imgui.INDEX_SIZE)
                )

Could you confirm that it works? If so, could you please send a PR?

Aman-Anas commented 6 months ago

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 https://github.com/ocornut/imgui/issues/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

pthom commented 6 months ago

Thanks, I'll answer in the PR