Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Qt pure c++ adding imgui
Forum Updated to NodeBB v4.3 + New Features

Qt pure c++ adding imgui

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
9 Posts 2 Posters 1.9k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    ekato993
    wrote on last edited by ekato993
    #1

    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
    
    1 Reply Last reply
    0
    • SGaistS SGaist

      Looks like you are missing the shell32 and imm32 libraries in your link list.

      E Offline
      E Offline
      ekato993
      wrote on last edited by
      #9

      @SGaist

      LIBS += -lglu32 -lgdi32 -lshell32 -limm32
      

      Works for me, thanks

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi,

        Aren't you missing the backend files ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        E 1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          Aren't you missing the backend files ?

          E Offline
          E Offline
          ekato993
          wrote on last edited by
          #3

          @SGaist

          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
          
          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #4

            Where are these methods located ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            E 1 Reply Last reply
            0
            • SGaistS SGaist

              Where are these methods located ?

              E Offline
              E Offline
              ekato993
              wrote on last edited by
              #5

              @SGaist

              Each methods in the imgui.h except the these methods:

              • GetTexDataAsRGBA32 is in the imgui_draw.cpp

              • Text and SliderFloat is in the imgui_widgets.cpp

              • ShowDemoWindow is in the imgui_demo.cpp

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #6

                Do you mean they are used or defined there ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                E 1 Reply Last reply
                0
                • SGaistS SGaist

                  Do you mean they are used or defined there ?

                  E Offline
                  E Offline
                  ekato993
                  wrote on last edited by
                  #7

                  @SGaist

                  They are defined there.

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #8

                    Looks like you are missing the shell32 and imm32 libraries in your link list.

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    E 1 Reply Last reply
                    1
                    • SGaistS SGaist

                      Looks like you are missing the shell32 and imm32 libraries in your link list.

                      E Offline
                      E Offline
                      ekato993
                      wrote on last edited by
                      #9

                      @SGaist

                      LIBS += -lglu32 -lgdi32 -lshell32 -limm32
                      

                      Works for me, thanks

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved