Search code examples
c++imgui

Sample application with imgui library generate error


I am new in imgui and just installed it with vcpkg and created an application in vs2022 and add these codes:

#include <imgui.h>
using namespace std;

void MySaveFunction()
{
}

int main()
{
    ImGui::Text("Hello, world %d", 123);
    if (ImGui::Button("Save"))
        MySaveFunction();
}

but when I run this application I get this error:

enter image description here

What minimum code do I need to display a window with a button on it?

I searched on the IMGUI website but could not find any simple sample that works.


Solution

  • Dear ImGui provided some detailed examples on how to get started.

    Don't be scared to read the code, which might be long and overwhelming if you are new to it.

    You basically need to choose a backend, I personally prefer DirectX 11. Then you have to create a window and initialize DirectX. Then create the ImGuiContext - which throws the error for g is nullptr because the context wasn't created, and initialize the backend after that.