-2

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.

mans
  • 17,104
  • 45
  • 172
  • 321

1 Answers1

1

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.

thedemons
  • 1,139
  • 2
  • 9
  • 25
  • I am using vcpkg and the documentation for this library stated that it is header only application. How can I build it using vcpkg and select a suitable backend? Adding CPP is not possible with vcpkg. – mans Oct 17 '22 at 22:40
  • @mans take a look at this [question](https://stackoverflow.com/questions/70254678/installing-dear-imgui-with-vcpkg-on-windows-10) – thedemons Oct 18 '22 at 05:14