Added PixelCenterOffset for OpenGL/DirectX compatibility.
diff --git a/examples/directx9_example/main.cpp b/examples/directx9_example/main.cpp
index fd25f01..017a3a9 100644
--- a/examples/directx9_example/main.cpp
+++ b/examples/directx9_example/main.cpp
@@ -293,6 +293,7 @@
io.KeyMap[ImGuiKey_X] = 'X';
io.KeyMap[ImGuiKey_Y] = 'Y';
io.KeyMap[ImGuiKey_Z] = 'Z';
+ io.PixelCenterOffset = 0.0f;
io.RenderDrawListsFn = ImImpl_RenderDrawLists;
io.SetClipboardTextFn = ImImpl_SetClipboardTextFn;
diff --git a/examples/opengl_example/main.cpp b/examples/opengl_example/main.cpp
index 909ffa9..2d23a74 100644
--- a/examples/opengl_example/main.cpp
+++ b/examples/opengl_example/main.cpp
@@ -297,6 +297,7 @@
io.KeyMap[ImGuiKey_X] = GLFW_KEY_X;
io.KeyMap[ImGuiKey_Y] = GLFW_KEY_Y;
io.KeyMap[ImGuiKey_Z] = GLFW_KEY_Z;
+ io.PixelCenterOffset = 0.5f;
io.RenderDrawListsFn = ImImpl_RenderDrawLists;
io.SetClipboardTextFn = ImImpl_SetClipboardTextFn;
diff --git a/imgui.cpp b/imgui.cpp
index 1ce8cce..4490177 100644
--- a/imgui.cpp
+++ b/imgui.cpp
@@ -262,6 +262,7 @@
LogFilename = "imgui_log.txt";
Font = NULL;
FontAllowScaling = false;
+ PixelCenterOffset = 0.5f;
MousePos = ImVec2(-1,-1);
MousePosPrev = ImVec2(-1,-1);
MouseDoubleClickTime = 0.30f;
@@ -5003,6 +5004,8 @@
float line_width = 0.0f;
const ImVec4 clip_rect = clip_rect_ref;
+ const float uv_offset = GImGui.IO.PixelCenterOffset;
+
float x = pos.x;
float y = pos.y;
for (const char* s = text_begin; s < text_end; s++)
@@ -5039,10 +5042,10 @@
continue;
}
- const float s1 = (0.0f + glyph->X) * tex_scale_x;
- const float t1 = (0.0f + glyph->Y) * tex_scale_y;
- const float s2 = (0.0f + glyph->X + glyph->Width) * tex_scale_x;
- const float t2 = (0.0f + glyph->Y + glyph->Height) * tex_scale_y;
+ const float s1 = (uv_offset + glyph->X) * tex_scale_x;
+ const float t1 = (uv_offset + glyph->Y) * tex_scale_y;
+ const float s2 = (uv_offset + glyph->X + glyph->Width) * tex_scale_x;
+ const float t2 = (uv_offset + glyph->Y + glyph->Height) * tex_scale_y;
out_vertices[0].pos = ImVec2(x1, y1);
out_vertices[0].uv = ImVec2(s1, t1);
diff --git a/imgui.h b/imgui.h
index 3c75057..d2e9041 100644
--- a/imgui.h
+++ b/imgui.h
@@ -373,6 +373,7 @@
ImFont Font; // <auto> // Gets passed to text functions. Typedef ImFont to the type you want (ImBitmapFont* or your own font).
float FontHeight; // <auto> // Default font height, must be the vertical distance between two lines of text, aka == CalcTextSize(" ").y
bool FontAllowScaling; // = false // Set to allow scaling text with CTRL+Wheel.
+ float PixelCenterOffset; // = 0.5f // Set to 0.0f for DirectX <= 9, 0.5f for Direct3D >= 10 and OpenGL.
// Settings - Functions (fill once)
void (*RenderDrawListsFn)(ImDrawList** const draw_lists, int count); // Required