This is a stupid simple method of implementing drop shadows in Dear ImGui.
First make a 9-slice texture that'll serve as your drop shadow. Here is the one I'm using for example:
Load it however you like. I'm not going to spoonfeed this since texture loading methods vary based on what graphics back-end ImGui is using. In any case, you'll need to have an ImTextureID available.
if (ImGui::Begin("Example"))
{
RenderDropShadow(shadow_tex, 24.0f, 100);
// Rest of your contents here...
ImGui::End();
}
If you want to abstract things further, you can implement your own Begin()
and use it in place of ImGui's. This will make it easier to do other style adjustments as well (for instance I like changing the border color, and I have some rules for when I can and cannot draw a drop shadow, e.g. docking)
namespace MyGui {
bool Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
{
bool active = ImGui::Begin(name, p_open, flags);
RenderDropShadow(...);
return active;
}
} // namespace MyGui
void Render()
{
if (MyGui::Begin())
{
// Rest of your contents here...
ImGui::End();
}
}
From ocornut/imgui#1329 (comment)