|
@@ -42,15 +42,18 @@ static void ImGui_ImplGlfwGL3_RenderDrawLists(ImDrawData* draw_data)
|
|
|
glEnable(GL_SCISSOR_TEST);
|
|
|
glActiveTexture(GL_TEXTURE0);
|
|
|
|
|
|
+ // Handle cases of screen coordinates != from framebuffer coordinates (e.g. retina displays)
|
|
|
+ ImGuiIO& io = ImGui::GetIO();
|
|
|
+ float fb_height = io.DisplaySize.y * io.DisplayFramebufferScale.y;
|
|
|
+ draw_data->ScaleClipRects(io.DisplayFramebufferScale);
|
|
|
+
|
|
|
// Setup orthographic projection matrix
|
|
|
- const float width = ImGui::GetIO().DisplaySize.x;
|
|
|
- const float height = ImGui::GetIO().DisplaySize.y;
|
|
|
const float ortho_projection[4][4] =
|
|
|
{
|
|
|
- { 2.0f/width, 0.0f, 0.0f, 0.0f },
|
|
|
- { 0.0f, 2.0f/-height, 0.0f, 0.0f },
|
|
|
- { 0.0f, 0.0f, -1.0f, 0.0f },
|
|
|
- { -1.0f, 1.0f, 0.0f, 1.0f },
|
|
|
+ { 2.0f/io.DisplaySize.x, 0.0f, 0.0f, 0.0f },
|
|
|
+ { 0.0f, 2.0f/-io.DisplaySize.y, 0.0f, 0.0f },
|
|
|
+ { 0.0f, 0.0f, -1.0f, 0.0f },
|
|
|
+ {-1.0f, 1.0f, 0.0f, 1.0f },
|
|
|
};
|
|
|
glUseProgram(g_ShaderHandle);
|
|
|
glUniform1i(g_AttribLocationTex, 0);
|
|
@@ -77,7 +80,7 @@ static void ImGui_ImplGlfwGL3_RenderDrawLists(ImDrawData* draw_data)
|
|
|
else
|
|
|
{
|
|
|
glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->TextureId);
|
|
|
- glScissor((int)pcmd->ClipRect.x, (int)(height - pcmd->ClipRect.w), (int)(pcmd->ClipRect.z - pcmd->ClipRect.x), (int)(pcmd->ClipRect.w - pcmd->ClipRect.y));
|
|
|
+ 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));
|
|
|
glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, GL_UNSIGNED_SHORT, idx_buffer_offset);
|
|
|
}
|
|
|
idx_buffer_offset += pcmd->ElemCount;
|
|
@@ -307,7 +310,8 @@ void ImGui_ImplGlfwGL3_NewFrame()
|
|
|
int display_w, display_h;
|
|
|
glfwGetWindowSize(g_Window, &w, &h);
|
|
|
glfwGetFramebufferSize(g_Window, &display_w, &display_h);
|
|
|
- io.DisplaySize = ImVec2((float)display_w, (float)display_h);
|
|
|
+ io.DisplaySize = ImVec2((float)w, (float)h);
|
|
|
+ io.DisplayFramebufferScale = ImVec2((float)display_w / w, (float)display_h / h);
|
|
|
|
|
|
// Setup time step
|
|
|
double current_time = glfwGetTime();
|
|
@@ -320,9 +324,7 @@ void ImGui_ImplGlfwGL3_NewFrame()
|
|
|
{
|
|
|
double mouse_x, mouse_y;
|
|
|
glfwGetCursorPos(g_Window, &mouse_x, &mouse_y);
|
|
|
- mouse_x *= (float)display_w / w; // Convert mouse coordinates to pixels
|
|
|
- mouse_y *= (float)display_h / h;
|
|
|
- io.MousePos = ImVec2((float)mouse_x, (float)mouse_y); // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.)
|
|
|
+ io.MousePos = ImVec2((float)mouse_x, (float)mouse_y); // Mouse position in screen coordinates (set to -1,-1 if no mouse / on another screen, etc.)
|
|
|
}
|
|
|
else
|
|
|
{
|