You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Originally posted by joramas August 13, 2023
Hi Omar!
I was using the normal UVRect [ImVec2(0.0f, 0.0f) to ImVec2(1.0f, 1.0f)] to render an image to the ImGui::ImageButton. I changed my sprite sheets packing algorithm to a polygon for tight packing, and now, instead of quads, I got an array of vertices and indices for each image. I've implemented the following functions, so anyone might find it helpful:
// ===========================================ImDrawList::PrimImageVerticesAndIndices (in imgui_draw.cpp)
ImDrawList::AddImagePolygon (in imgui_draw.cpp)
ImGui::ImagePolygonButton (in imgui_widgets.cpp)
// ===========================================
NOTE: I use TexturePacker for sprite_sheet creation, so I had to adjust the alignment in the image button quad, but aside from that, anyone should adapt it to its necessities as wanted. At the end, there is an image of how it looks.
Linking to #845#2942#4722 for visibility of similar techniques.
Please note that you shouldn't need to modify imgui files to implement this:
the ImGui::ImagePolygonButton() function can be declared and implemented in your own source file.
ImDrawList being a class instead of a namespace you cannot do it the same way, but you can call your function e.g. void ImDrawList_AddImagePolygon(ImDrawList* draw_list, ....) and it'll work.
Nowadays I regret making ImDrawList use methods instead of loose functions, as the later makes it slightly easier to extend. maybe something we will reconsider in 2.0.
Discussed in https://github.com/ocornut/imgui/discussions/6712
Originally posted by joramas August 13, 2023
Hi Omar!
I was using the normal UVRect [ImVec2(0.0f, 0.0f) to ImVec2(1.0f, 1.0f)] to render an image to the ImGui::ImageButton. I changed my sprite sheets packing algorithm to a polygon for tight packing, and now, instead of quads, I got an array of vertices and indices for each image. I've implemented the following functions, so anyone might find it helpful:
NOTE: I use TexturePacker for sprite_sheet creation, so I had to adjust the alignment in the image button quad, but aside from that, anyone should adapt it to its necessities as wanted. At the end, there is an image of how it looks.
The text was updated successfully, but these errors were encountered: