imgui
imgui copied to clipboard
Line not drawing at the points I specify
Apologies if this has been addressed before but I didn't find anything from a quick Google search.
I have the following code:
auto dl = ImGui::GetForegroundDrawList();
vec2 offset = {10, 10};
dl->AddRectFilled(offset, offset + vec2(100, 100), 0xFFFFFFFF);
dl->AddRectFilled(offset + vec2(0, 100), offset + vec2(100, 200), 0xFF000000);
dl->AddLine(offset + vec2(50, 0), offset + vec2(50, 100), 0xFF0000FF);
The line is being drawn 1 pixel lower than it should be, on the start and end points. Here's what it looks like:
I'm probably just doing something stupid here but, I really don't understand why this happens!
Hello @sci4me ,
Could you specify your rendering back-ends as requested by the issue template? Also linking to #3116 and #2441.
Ah, sorry about that @ocornut! Was being lazy and went quickly :P
I am using imgui_impl_glfw
and imgui_impl_opengl3
.
The only thing I'm going to ask you if you post there is to not be lazy, fill the requested forms and do some searching. I'm spending dozen hours every week answering people problems here so any help is appreciated.
@ocornut Absolutely; I'm on the same page. Frankly, my lazy posting goes against my own values so I really mean it when I say I'm sorry about that.
Regarding the issue, I would tell you what commit I'm using but I've been a bad developer and currently I only have the minimum source files, etc. checked into my repo, so I'm not really sure what commit it would be. Lesson learned! :P Perhaps I should just update to latest and properly keep track of that.
That rendering code haven't changed in a while so commit # isn't so important, best to specify version (mentioned in all dear imgui sources files) in general but here it won't make a difference.
I cannot repro here with DX11 nor OpenGL with:
ImDrawList* dl = ImGui::GetForegroundDrawList();
ImVec2 offset(10, 10);
dl->AddRectFilled(offset, ImVec2(offset.x + 100, offset.y + 100), 0xFFFFFFFF);
dl->AddRectFilled(ImVec2(offset.x + 0, offset.y + 100), ImVec2(offset.x + 100, offset.y + 200), 0xFF000000);
dl->AddLine(ImVec2(offset.x + 50, offset.y + 0), ImVec2(offset.x + 50, offset.y + 100), 0xFF0000FF);
Does this repro for you in the unmodified examples/ application?
Yes, I just checked out the repo and added that snippet into the GLFW OpenGL 3 example right after the call to ImGui::NewFrame, and it does repro on my machine.
Which operating system, video card and drivers? (Another thing requested by the issue template!) Thank you.
OS: Linux 5.6.14-arch1-1 x86_64 Video Card: MSI RTX 2060 (Rev. A supposedly) Driver: nvidia 440.82-17 (through the Arch Linux package) Compiler: g++ (gcc) 10.1.0
Can not reproduce here. OS: Linux 5.6.10-arch1-1 GPU: RX 580 Driver: amdgpu Mesa: v20.0.6
I have taken the GLFW+OpenGL3 example and modified it to be a relatively minimal program that, on my machine, repros this issue. (I'm really starting to wonder if it's my hardware specifically or something...)
Here's how I built in:
g++ -I../ -I../../ ../imgui_impl_glfw.cpp ../imgui_impl_opengl3.cpp ../../imgui.cpp ../../imgui_draw.cpp ../../imgui_widgets.cpp main.cpp -o example_glfw_opengl3 -lGLEW -lglfw -lGL -DIMGUI_IMPL_OPENGL_LOADER_GLEW
I just ran that from the same example directory.
And the code:
Expand Me
#define DIMGUI_IMPL_OPENGL_LOADER_GLEW
#include "imgui.h"
#include "imgui_impl_glfw.h"
#include "imgui_impl_opengl3.h"
#include <stdio.h>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
static void glfw_error_callback(int error, const char* description) {
fprintf(stderr, "Glfw Error %d: %s\n", error, description);
}
int main(int, char**) {
glfwSetErrorCallback(glfw_error_callback);
if (!glfwInit())
return 1;
const char* glsl_version = "#version 130";
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
GLFWwindow* window = glfwCreateWindow(1280, 720, "Dear ImGui GLFW+OpenGL3 example", NULL, NULL);
if (window == NULL)
return 1;
glfwMakeContextCurrent(window);
glfwSwapInterval(1);
if (glewInit() != GLEW_OK) {
fprintf(stderr, "Failed to initialize GLEW!\n");
return 1;
}
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io;
ImGui::StyleColorsDark();
ImGui_ImplGlfw_InitForOpenGL(window, true);
ImGui_ImplOpenGL3_Init(glsl_version);
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
{
ImDrawList* dl = ImGui::GetForegroundDrawList();
ImVec2 offset(10, 10);
dl->AddRectFilled(offset, ImVec2(offset.x + 100, offset.y + 100), 0xFFFFFFFF);
dl->AddRectFilled(ImVec2(offset.x + 0, offset.y + 100), ImVec2(offset.x + 100, offset.y + 200), 0xFF000000);
dl->AddLine(ImVec2(offset.x + 50, offset.y + 0), ImVec2(offset.x + 50, offset.y + 100), 0xFF0000FF);
}
ImGui::Render();
int display_w, display_h;
glfwGetFramebufferSize(window, &display_w, &display_h);
glViewport(0, 0, display_w, display_h);
glClearColor(0, 0, 1, 1);
glClear(GL_COLOR_BUFFER_BIT);
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
glfwSwapBuffers(window);
}
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
glfwDestroyWindow(window);
glfwTerminate();
return 0;
}
Let me know if there's anything else I can provide that I'm forgetting!
It's good you provided the example. I cannot reproduce on current master 3f26a07ee1813cecaa87253436149e28fc11dc4e arch IVB GT2
The same issue. Backend: imgui_impl_glfw / imgui_impl_opengl3 OS: Linux raspi 6.1.0-rpi8-rpi-v8 #1 SMP PREEMPT Debian 1:6.1.73-1+rpt1 (2024-01-25) aarch64 GNU/Linux HW: Raspberry Pi 4B rev 1.5 OpenGL: 3.1 Mesa 23.2.1-1~bpo12+rpt3
Any idea how to fix it? I tried to add offsets, but it don't helps.
Here is test code to reproduce it:
#define DIMGUI_IMPL_OPENGL_LOADER_GLEW
#include "imgui.h"
#include "imgui_impl_glfw.h"
#include "imgui_impl_opengl3.h"
#include <stdio.h>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
static void glfw_error_callback(int error, const char* description) {
fprintf(stderr, "Glfw Error %d: %s\n", error, description);
}
int main(int, char**) {
glfwSetErrorCallback(glfw_error_callback);
if (!glfwInit())
return 1;
const char* glsl_version = "#version 130";
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
GLFWwindow* window = glfwCreateWindow(800, 600, "Dear ImGui GLFW+OpenGL3 example", NULL, NULL);
if (window == NULL)
return 1;
glfwMakeContextCurrent(window);
glfwSwapInterval(1);
if (glewInit() != GLEW_OK) {
fprintf(stderr, "Failed to initialize GLEW!\n");
return 1;
}
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io;
ImGui::StyleColorsDark();
ImGui_ImplGlfw_InitForOpenGL(window, true);
ImGui_ImplOpenGL3_Init(glsl_version);
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
{
ImDrawList* dl = ImGui::GetForegroundDrawList();
ImVec2 offset(12, 12);
dl->AddRectFilled(offset, ImVec2(offset.x + 100, offset.y + 100), 0xFFFFFFFF);
dl->AddRectFilled(ImVec2(offset.x + 0, offset.y + 100), ImVec2(offset.x + 100, offset.y + 200), 0xFF000000);
dl->AddLine(ImVec2(offset.x + 50, offset.y + 0), ImVec2(offset.x + 50, offset.y + 100), 0xFF0000FF);
auto x = offset.x + 10;
auto y = offset.y + 10;
auto scale = 1.0;
dl->AddLine(ImVec2(x, y),
ImVec2(x-5, y+5),
IM_COL32(255, 0, 0, 255), scale);
dl->AddLine(ImVec2(x, y),
ImVec2(x+5, y+5),
IM_COL32(255, 0, 0, 255), scale);
dl->AddLine(ImVec2(x-5, y+5),
ImVec2(x+5, y+5),
IM_COL32(255, 0, 0, 255), scale);
y += 15;
dl->AddLine(ImVec2(x, y),
ImVec2(x-5, y-5),
IM_COL32(255, 0, 0, 255), scale);
dl->AddLine(ImVec2(x, y),
ImVec2(x+5, y-5),
IM_COL32(255, 0, 0, 255), scale);
dl->AddLine(ImVec2(x-5, y-5),
ImVec2(x+5, y-5),
IM_COL32(255, 0, 0, 255), scale);
}
ImGui::Render();
int display_w, display_h;
glfwGetFramebufferSize(window, &display_w, &display_h);
glViewport(0, 0, display_w, display_h);
glClearColor(0, 0, 1, 1);
glClear(GL_COLOR_BUFFER_BIT);
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
glfwSwapBuffers(window);
}
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
glfwDestroyWindow(window);
glfwTerminate();
return 0;
}
Here is the issue:
Here what is expected: