Using this one:
https://github.com/eliasdaler/imgui-sfml. It is quite easy to setup.
- Right click your project -> Properties
- Change Configuration on top to All Configurations
- Go to C/C++ -> General -> Additional Include Directories
- Add the imgui (https://github.com/ocornut/imgui) folder path in there
- Open up imconfig-SFML.h and imconfig.h. Add the contents of imconfig-SFML.h inside imconfig.h in their proper positions in the top of the file (#include with the other includes, defines with the other defines, etc...).
- Add the following files to your project: imgui.cpp, imgui_draw.cpp, imgui-SFML.cpp
Try out this test program:
#include <imgui.h>
#include <imgui-sfml\imgui-SFML.h>
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/System/Clock.hpp>
#include <SFML/Window/Event.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(640, 480), "");
window.setVerticalSyncEnabled(true);
ImGui::SFML::Init(window);
sf::Color bgColor;
float color[3] = { 0.f, 0.f, 0.f };
// let's use char array as buffer, see next part
// for instructions on using std::string with ImGui
char windowTitle[255] = "ImGui + SFML = <3";
window.setTitle(windowTitle);
window.resetGLStates(); // call it if you only draw ImGui. Otherwise not needed.
sf::Clock deltaClock;
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
ImGui::SFML::ProcessEvent(event);
if (event.type == sf::Event::Closed) {
window.close();
}
}
ImGui::SFML::Update(window, deltaClock.restart());
ImGui::Begin("Sample window"); // begin window
// Background color edit
if (ImGui::ColorEdit3("Background color", color))
{
// this code gets called if color value changes, so
// the background color is upgraded automatically!
bgColor.r = static_cast<sf::Uint8>(color[0] * 255.f);
bgColor.g = static_cast<sf::Uint8>(color[1] * 255.f);
bgColor.b = static_cast<sf::Uint8>(color[2] * 255.f);
}
// Window title text edit
ImGui::InputText("Window title", windowTitle, 500);
if (ImGui::Button("Update window title"))
{
// this code gets if user clicks on the button
// yes, you could have written if(ImGui::InputText(...))
// but I do this to show how buttons work :)
window.setTitle(windowTitle);
}
ImGui::End(); // end window
window.clear(bgColor); // fill background with color
ImGui::Render();
window.display();
}
ImGui::SFML::Shutdown();
}
I am using Visual Studio 2017 as well and it works great without any errors. All the instructions take from here:
https://eliasdaler.github.io/using-imgui-with-sfml-pt1/. I had to change the following two lines in the test program:
#include "imgui.h"
#include "imgui-sfml.h"
to this:
#include <imgui.h>
#include <imgui-sfml\imgui-SFML.h>
to make it work. Though if you want to stay to the original then you just include the imgui-SFML directory as well. Hope this helps!
EDIT: If the problem still persists, the link mentions to try linking OpenGL to your project.