Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Gryfenfer
Gryfenfer

Posted on • Edited on

     

How to install imgui-sfml from conan

Conan is a powerful C++ package manager which simplify a lot the dependency managment in your projects.

Here I will talk about the installation of imgui-sfml from the perspective of someone who has never used it.

Requirements

To follow this tutorial you will need to have on your machine :

  • Python3 (we will use pip to install conan)
  • CMake

Conan Installation

First we will need to install conan.
In your project directory run

$python-m venv venv$sourcevenv/bin/activate$pipinstallconan$conan$conan remote add bincrafters https://bincrafters.jfrog.io/artifactory/api/conan/conan
Enter fullscreen modeExit fullscreen mode

Here is the expected output :
Output of the command  raw `conan` endraw

To deactivate the virtualenv just run

$deactivate

Let's build the project

In this section we will use CMake but if you want to use any other generator the documentation ishere.

As there is no package for imgui-sfml in conan-center we will need to download it frombincrafters.

For that we need to create aconanfile.txt at the root of the project.
./conanfile.txt

[requires]imgui-sfml/2.3@bincrafters/stable[generator]cmake
Enter fullscreen modeExit fullscreen mode

Next add those two line in yourCMakeLists.txt.
./CMakeLists.txt

cmake_minimum_required(VERSION 3.16)project(MyProject)+include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)+conan_basic_setup()...
Enter fullscreen modeExit fullscreen mode

Then create the build folder and install the dependencies.

$mkdirbuild$conaninstall.--install-folder ./build# You will have some error but that's normal
Enter fullscreen modeExit fullscreen mode

The point of the last command was to generate the file~/.conan/profile/default.

Change the libcxx version

SFML which is a dependancy of imgui-sfml needs the libstdc++11 to work properly. However conan still use libstdc++ by default for backwards compatibility so you have to edit it by yourself.

Run the command:

conan profile update settings.compiler.libcxx=libstdc++11 default
Enter fullscreen modeExit fullscreen mode

or

Open the file~/.conan/profile/default and apply the following change

-compiler.libcxx=libstdc+++compiler.libcxx=libstdc++11
Enter fullscreen modeExit fullscreen mode

Go back to the project

Here is a code sample (fromhere) to test imgui-sfml.

#include"imgui.h"#include"imgui-SFML.h"#include<SFML/Graphics/RenderWindow.hpp>#include<SFML/System/Clock.hpp>#include<SFML/Window/Event.hpp>intmain(){sf::RenderWindowwindow(sf::VideoMode(640,480),"");window.setVerticalSyncEnabled(true);ImGui::SFML::Init(window);sf::ColorbgColor;floatcolor[3]={0.f,0.f,0.f};// let's use char array as buffer, see next part// for instructions on using std::string with ImGuicharwindowTitle[255]="ImGui + SFML = <3";window.setTitle(windowTitle);window.resetGLStates();// call it if you only draw ImGui. Otherwise not needed.sf::ClockdeltaClock;while(window.isOpen()){sf::Eventevent;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 editif(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 editImGui::InputText("Window title",windowTitle,255);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 windowwindow.clear(bgColor);// fill background with colorImGui::SFML::Render(window);window.display();}ImGui::SFML::Shutdown();}
Enter fullscreen modeExit fullscreen mode

Then in your project

$conaninstall.--install-folder ./build# Now you should not have any error$cmake.-Bbuild$cmake--build build$./build/bin/app
Enter fullscreen modeExit fullscreen mode

Once that's finished enjoy your application 😉.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

C++ dev, AI enthousiast and JPEG scalpel
  • Location
    France
  • Education
    Engineering school
  • Work
    Student
  • Joined

Trending onDEV CommunityHot

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp