Qt pure c++ adding imgui
Moved
Solved
Qt Creator and other tools
-
I would like to add imgui into with "pure" c++ code.
I am using Qt5 and win10 and I am using non-qt project, plain c++ application
include\GLFW\glfw3.h linking\GLFW\glfw3.dll linking\GLFW\glfw3dll.a linking\GLFW\libglfw3.a
.pro file
TEMPLATE = app CONFIG += console c++11 CONFIG -= app_bundle CONFIG -= qt HEADERS += \ imgui.h \ imconfig.h \ imgui_internal.h \ imstb_rectpack.h \ imstb_textedit.h \ imstb_truetype.h \ SOURCES += \ main.cpp \ imgui.cpp \ imgui_demo.cpp \ imgui_draw.cpp \ imgui_tables.cpp \ imgui_widgets.cpp LIBS += -L$$PWD/linking/GLFW/ -lglfw3 -lopengl32 LIBS += -lglu32 -lgdi32 INCLUDEPATH += $$PWD/linking/GLFW DEPENDPATH += $$PWD/linking/GLFW INCLUDEPATH += $$PWD/include DEPENDPATH += $$PWD/include
main.cpp
#include "imgui.h" #include <stdio.h> int main(int, char**) { IMGUI_CHECKVERSION(); ImGui::CreateContext(); ImGuiIO& io = ImGui::GetIO(); // Build atlas unsigned char* tex_pixels = NULL; int tex_w, tex_h; io.Fonts->GetTexDataAsRGBA32(&tex_pixels, &tex_w, &tex_h); for (int n = 0; n < 20; n++) { printf("NewFrame() %d\n", n); io.DisplaySize = ImVec2(1920, 1080); io.DeltaTime = 1.0f / 60.0f; ImGui::NewFrame(); static float f = 0.0f; ImGui::Text("Hello, world!"); ImGui::SliderFloat("float", &f, 0.0f, 1.0f); ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate); ImGui::ShowDemoWindow(NULL); ImGui::Render(); } printf("DestroyContext()\n"); ImGui::DestroyContext(); return 0; }
main.cpp is an example file from imgui/example/example-null folder: link
On qt create I click on Rebuild All Project for All Configuration I'am getting the follwoing errors:
...\build-untitled-Desktop_Qt_5_12_11_MinGW_64_bit-Debug\..\untitled\imgui.cpp:10811: error: undefined reference to `ImmGetContext' debug/imgui.o: In function `ImeSetInputScreenPosFn_DefaultImpl': ...\build-untitled-Desktop_Qt_5_12_11_MinGW_64_bit-Debug/../untitled/imgui.cpp:10811: undefined reference to `ImmGetContext' ...\build-untitled-Desktop_Qt_5_12_11_MinGW_64_bit-Debug\..\untitled\imgui.cpp:10817: error: undefined reference to `ImmSetCompositionWindow' ...\build-untitled-Desktop_Qt_5_12_11_MinGW_64_bit-Debug\..\untitled\imgui.cpp:10818: error: undefined reference to `ImmReleaseContext' :-1: error: collect2.exe: error: ld returned 1 exit status :-1: error: [Makefile.Debug:85: debug/untitled.exe] Error 1
-
Hi,
Aren't you missing the backend files ?
-
I have copyed the
imgui_impl_opengl3.h/cpp
into my folder and now my .pro looks like this:TEMPLATE = app CONFIG += console c++11 CONFIG -= app_bundle CONFIG -= qt HEADERS += \ imgui.h \ imconfig.h \ imgui_internal.h \ imstb_rectpack.h \ imstb_textedit.h \ imstb_truetype.h \ imgui_impl_opengl3.h SOURCES += \ main.cpp \ imgui.cpp \ imgui_demo.cpp \ imgui_draw.cpp \ imgui_tables.cpp \ imgui_widgets.cpp \ imgui_impl_opengl3.cpp \ glad.c LIBS += -L$$PWD/linking/GLFW/ -lglfw3 -lopengl32 LIBS += -lglu32 -lgdi32 INCLUDEPATH += $$PWD/linking/GLFW DEPENDPATH += $$PWD/linking/GLFW INCLUDEPATH += $$PWD/include DEPENDPATH += $$PWD/include
I need to add the following files as well:
include\glad\glad.h include\KHR\khrplatform.h
main.cpp
#include "imgui.h" #include <glad/glad.h> #include <stdio.h> int main(int, char**) { gladLoadGL(); //imgui_impl_opengl3.cpp says: Needs to be initialized with gladLoadGL() in user's code IMGUI_CHECKVERSION(); ImGui::CreateContext(); ImGuiIO& io = ImGui::GetIO(); // Build atlas unsigned char* tex_pixels = NULL; int tex_w, tex_h; io.Fonts->GetTexDataAsRGBA32(&tex_pixels, &tex_w, &tex_h); for (int n = 0; n < 20; n++) { printf("NewFrame() %d\n", n); io.DisplaySize = ImVec2(1920, 1080); io.DeltaTime = 1.0f / 60.0f; ImGui::NewFrame(); static float f = 0.0f; ImGui::Text("Hello, world!"); ImGui::SliderFloat("float", &f, 0.0f, 1.0f); ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate); ImGui::ShowDemoWindow(NULL); ImGui::Render(); } printf("DestroyContext()\n"); ImGui::DestroyContext(); return 0; }
I am getting the following errors:
...\build-untitled-Desktop_Qt_5_12_11_MinGW_64_bit-Debug\..\untitled\imgui.cpp:10811: error: undefined reference to `ImmGetContext' debug/imgui.o: In function `ImeSetInputScreenPosFn_DefaultImpl': ...\build-untitled-Desktop_Qt_5_12_11_MinGW_64_bit-Debug/../untitled/imgui.cpp:10811: undefined reference to `ImmGetContext' ...\build-untitled-Desktop_Qt_5_12_11_MinGW_64_bit-Debug\..\untitled\imgui.cpp:10817: error: undefined reference to `ImmSetCompositionWindow' ...\build-untitled-Desktop_Qt_5_12_11_MinGW_64_bit-Debug\..\untitled\imgui.cpp:10818: error: undefined reference to `ImmReleaseContext' :-1: error: collect2.exe: error: ld returned 1 exit status :-1: error: [Makefile.Debug:92: debug/untitled.exe] Error 1
-
Where are these methods located ?
-
Do you mean they are used or defined there ?
-
Looks like you are missing the shell32 and imm32 libraries in your link list.