Skip to content

Commit 52dd94b

Browse files
authored
Merge pull request #50 from dimateos/pr/fix-modalbg
FIX: modal background + improve clipping
2 parents 48d64a7 + 559a368 commit 52dd94b

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/ImGuiRenderer.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ void ImGuiRenderer::renderDrawList(ImDrawData *draw_data)
158158
glUniformMatrix4fv(g_AttribLocationProjMtx, 1, GL_FALSE, &ortho_projection[0][0]);
159159
glBindVertexArray(g_VaoHandle);
160160

161+
// Will project scissor/clipping rectangles into framebuffer space
162+
ImVec2 clip_off = draw_data->DisplayPos; // (0,0) unless using multi-viewports
163+
ImVec2 clip_scale = draw_data->FramebufferScale; // (1,1) unless using retina display which are often (2,2)
164+
161165
for (int n = 0; n < draw_data->CmdListsCount; n++)
162166
{
163167
const ImDrawList* cmd_list = draw_data->CmdLists[n];
@@ -178,11 +182,19 @@ void ImGuiRenderer::renderDrawList(ImDrawData *draw_data)
178182
}
179183
else
180184
{
185+
// Project scissor/clipping rectangles into framebuffer space
186+
ImVec2 clip_min((pcmd->ClipRect.x - clip_off.x) * clip_scale.x, (pcmd->ClipRect.y - clip_off.y) * clip_scale.y);
187+
ImVec2 clip_max((pcmd->ClipRect.z - clip_off.x) * clip_scale.x, (pcmd->ClipRect.w - clip_off.y) * clip_scale.y);
188+
if (clip_max.x <= clip_min.x || clip_max.y <= clip_min.y)
189+
continue;
190+
191+
// Apply scissor/clipping rectangle (Y is inverted in OpenGL)
192+
glScissor((int)clip_min.x, (int)(fb_height - clip_max.y), (int)(clip_max.x - clip_min.x), (int)(clip_max.y - clip_min.y));
193+
194+
// Bind texture, Draw
181195
glBindTexture(GL_TEXTURE_2D, (GLuint)(size_t)pcmd->TextureId);
182-
glScissor((int)pcmd->ClipRect.x, (int)(fb_height - pcmd->ClipRect.w), (int)(pcmd->ClipRect.z - pcmd->ClipRect.x), (int)(pcmd->ClipRect.w - pcmd->ClipRect.y));
183-
glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer_offset);
196+
glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer_offset + pcmd->IdxOffset);
184197
}
185-
idx_buffer_offset += pcmd->ElemCount;
186198
}
187199
}
188200

0 commit comments

Comments
 (0)