{"id":15034713,"url":"https://github.com/sfml/imgui-sfml","last_synced_at":"2026-01-12T06:16:36.405Z","repository":{"id":7066000,"uuid":"56048623","full_name":"SFML/imgui-sfml","owner":"SFML","description":"Dear ImGui backend for use with SFML","archived":false,"fork":false,"pushed_at":"2025-03-09T17:46:44.000Z","size":385,"stargazers_count":1208,"open_issues_count":27,"forks_count":178,"subscribers_count":32,"default_branch":"master","last_synced_at":"2025-04-29T15:33:51.715Z","etag":null,"topics":["binding","gui","imgui","immediate-gui","sfml"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SFML.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-04-12T09:16:31.000Z","updated_at":"2025-04-27T17:00:54.000Z","dependencies_parsed_at":"2023-07-28T13:16:41.177Z","dependency_job_id":"51b1a9c4-75f6-44b6-9c8b-865bf305af84","html_url":"https://github.com/SFML/imgui-sfml","commit_stats":{"total_commits":345,"total_committers":51,"mean_commits":6.764705882352941,"dds":0.6173913043478261,"last_synced_commit":"3eb1ece0fed8351e89e69d4f72cf762ac1c4f4cf"},"previous_names":["eliasdaler/imgui-sfml"],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SFML%2Fimgui-sfml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SFML%2Fimgui-sfml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SFML%2Fimgui-sfml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SFML%2Fimgui-sfml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SFML","download_url":"https://codeload.github.com/SFML/imgui-sfml/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254160229,"owners_count":22024567,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["binding","gui","imgui","immediate-gui","sfml"],"created_at":"2024-09-24T20:26:05.811Z","updated_at":"2026-01-12T06:16:36.399Z","avatar_url":"https://github.com/SFML.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"ImGui-SFML\n==========\n\nLibrary which allows you to use [Dear ImGui](https://github.com/ocornut/imgui) with [SFML](https://github.com/SFML/SFML)\n\n![screenshot](https://i2.wp.com/i.imgur.com/iQibpSk.gif)\n\nBased on [this repository](https://github.com/Mischa-Alff/imgui-backends) with big improvements and changes.\n\nState of Development\n-----\n\nDevelopment is focused on version 3 in the `master` branch.\nNo more features are planned for the 2.x release series.\n\nDependencies\n-----\n\n* [SFML](https://github.com/SFML/SFML) \u003e= 3.0.0\n* [Dear ImGui](https://github.com/ocornut/imgui) \u003e= 1.91.1, \u003c 1.92.0\n\nContributing\n-----\n\n* The code is written in C++17 (SFML 3 uses C++17, Dear ImGui has started using C++11 since 2022)\n* The code should be formatted via [ClangFormat](https://clang.llvm.org/docs/ClangFormat.html) using `.clang-format` provided in the root of this repository\n\nHow-to\n----\n\n- [**CMake tutorial which also shows how to use ImGui-SFML with FetchContent**](https://edw.is/using-cmake/)\n- [**Example project which sets up ImGui-SFML with FetchContent**](https://github.com/eliasdaler/cmake-fetchcontent-tutorial-code)\n- [**Detailed tutorial on Elias Daler's blog**](https://edw.is/using-imgui-with-sfml-pt1)\n- [**Using ImGui with modern C++ and STL**](https://edw.is/using-imgui-with-sfml-pt2/)\n- [**Thread on SFML forums**](https://en.sfml-dev.org/forums/index.php?topic=20137.0). Feel free to ask your questions there.\n\nBuilding and integrating into your CMake project\n---\nIt's highly recommended to use FetchContent or git submodules to get SFML and Dear ImGui into your build.\n\nSee [this file](https://github.com/eliasdaler/imgui-sfml-fetchcontent/blob/master/dependencies/CMakeLists.txt) - if you do something similar, you can then just link to ImGui-SFML as simply as:\n\n```cmake\ntarget_link_libraries(game\n  PUBLIC\n    ImGui-SFML::ImGui-SFML\n)\n```\n\nIntegrating into your project manually\n---\n- Download [ImGui](https://github.com/ocornut/imgui)\n- Add Dear ImGui folder to your include directories\n- Add `imgui.cpp`, `imgui_widgets.cpp`, `imgui_draw.cpp` and `imgui_tables.cpp` to your build/project\n- Copy the contents of `imconfig-SFML.h` to your `imconfig.h` file. (to be able to cast `ImVec2` to `sf::Vector2f` and vice versa)\n- Add a folder which contains `imgui-SFML.h` to your include directories\n- Add `imgui-SFML.cpp` to your build/project\n- Link OpenGL if you get linking errors\n\nOther ways to add to your project\n---\nNot recommended, as they're not maintained officially. Tend to lag behind and stay on older versions.\n\n- [Conan](https://github.com/bincrafters/community/tree/main/recipes/imgui-sfml)\n- [vcpkg](https://github.com/microsoft/vcpkg/tree/master/ports/imgui-sfml)\n- [Bazel](https://github.com/zpervan/ImguiSFMLBazel)\n\nUsing ImGui-SFML in your code\n---\n\n- Call `ImGui::SFML::Init` and pass your `sf::Window` + `sf::RenderTarget` or `sf::RenderWindow` there. You can create your font atlas and pass the pointer in Init too, otherwise the default internal font atlas will be created for you. Do this for each window you want to draw ImGui on.\n- For each iteration of a game loop:\n    - Poll and process events:\n\n        ```cpp\n        while (const auto event = window.pollEvent()) {\n            ImGui::SFML::ProcessEvent(window, *event);\n            ...\n        }\n        ```\n\n    - Call `ImGui::SFML::Update(window, deltaTime)` where `deltaTime` is `sf::Time`. You can also pass `mousePosition` and `displaySize` yourself instead of passing the window.\n    - Call ImGui functions (`ImGui::Begin()`, `ImGui::Button()`, etc.)\n    - Call `ImGui::EndFrame` after the last `ImGui::End` in your update function, if you update more than once before rendering. (e.g. fixed delta game loops)\n    - Call `ImGui::SFML::Render(window)`\n\n- Call `ImGui::SFML::Shutdown()` **after** `window.close()` has been called\n    - Use `ImGui::SFML::Shutdown(window)` overload if you have multiple windows. After it's called one of the current windows will become a current \"global\" window. Call `SetCurrentWindow` to explicitly set which window will be used as default.\n\n**If you only draw ImGui widgets without any SFML stuff, then you'll might need to call window.resetGLStates() before rendering anything. You only need to do it once.**\n\nExample code\n----\n\nSee example file [here](https://github.com/SFML/imgui-sfml/blob/master/examples/minimal/main.cpp)\n\n```cpp\n#include \"imgui.h\"\n#include \"imgui-SFML.h\"\n\n#include \u003cSFML/Graphics/CircleShape.hpp\u003e\n#include \u003cSFML/Graphics/RenderWindow.hpp\u003e\n#include \u003cSFML/System/Clock.hpp\u003e\n#include \u003cSFML/Window/Event.hpp\u003e\n\nint main() {\n    sf::RenderWindow window(sf::VideoMode({640, 480}), \"ImGui + SFML = \u003c3\");\n    window.setFramerateLimit(60);\n    ImGui::SFML::Init(window);\n\n    sf::CircleShape shape(100.f);\n    shape.setFillColor(sf::Color::Green);\n\n    sf::Clock deltaClock;\n    while (window.isOpen()) {\n        while (const auto event = window.pollEvent()) {\n            ImGui::SFML::ProcessEvent(window, *event);\n\n            if (event-\u003eis\u003csf::Event::Closed\u003e()) {\n                window.close();\n            }\n        }\n\n        ImGui::SFML::Update(window, deltaClock.restart());\n\n        ImGui::ShowDemoWindow();\n\n        ImGui::Begin(\"Hello, world!\");\n        ImGui::Button(\"Look at this pretty button\");\n        ImGui::End();\n\n        window.clear();\n        window.draw(shape);\n        ImGui::SFML::Render(window);\n        window.display();\n    }\n\n    ImGui::SFML::Shutdown();\n}\n```\n\nFonts how-to\n---\n\nDefault font is loaded if you don't pass `false` in `ImGui::SFML::Init`. Call `ImGui::SFML::Init(window, false);` if you don't want default font to be loaded.\n\n* Load your fonts like this:\n\n```cpp\nIO.Fonts-\u003eClear(); // clear fonts if you loaded some before (even if only default one was loaded)\n// IO.Fonts-\u003eAddFontDefault(); // this will load default font as well\nIO.Fonts-\u003eAddFontFromFileTTF(\"font1.ttf\", 8.f);\nIO.Fonts-\u003eAddFontFromFileTTF(\"font2.ttf\", 12.f);\n\nImGui::SFML::UpdateFontTexture(); // important call: updates font texture\n```\n\n* And use them like this:\n\n```cpp\nImGui::PushFont(ImGui::GetIO().Fonts-\u003eFonts[0]);\nImGui::Button(\"Look at this pretty button\");\nImGui::PopFont();\n\nImGui::PushFont(ImGui::GetIO().Fonts-\u003eFonts[1]);\nImGui::TextUnformatted(\"IT WORKS!\");\nImGui::PopFont();\n```\n\nThe first loaded font is treated as the default one and doesn't need to be pushed with `ImGui::PushFont`.\n\nMultiple windows\n----------------\n\nSee `examples/multiple_windows` to see how you can create multiple SFML and run different ImGui contexts in them.\n\n- Don't forget to run `ImGui::SFML::Init(const sf::Window\u0026)` for each window you create. Same goes for `ImGui::SFML::Shutdown(const sf::Window\u0026)`\n- Instead of calling `ImGui::SFML::ProcessEvent(sf::Event\u0026)`, you need to call `ImGui::SFML::ProcessEvent(const sf::Window\u0026, const sf::Event\u0026)` overload for each window you create\n- Call `ImGui::SFML::SetCurrentWindow` before calling any `ImGui` functions (e.g. `ImGui::Begin`, `ImGui::Button` etc.)\n- Either call `ImGui::Render(sf::RenderWindow\u0026)` overload for each window or manually do this:\n    ```cpp\n    SetCurrentWindow(window);\n    ... // your custom rendering\n    ImGui::Render();\n\n    SetCurrentWindow(window2);\n    ... // your custom rendering\n    ImGui::Render();\n    ```\n- When closing everything: don't forget to close all windows using SFML's `sf::Window::Close` and then call `ImGui::SFML::Shutdown` to remote all ImGui-SFML window contexts and other data.\n\nSFML related ImGui overloads / new widgets\n---\n\nThere are some useful overloads implemented for SFML objects (see `imgui-SFML.h` for other overloads):\n\n```cpp\nImGui::Image(const sf::Sprite\u0026 sprite);\nImGui::Image(const sf::Texture\u0026 texture);\nImGui::Image(const sf::RenderTexture\u0026 texture);\n\nImGui::ImageButton(const sf::Sprite\u0026 sprite);\nImGui::ImageButton(const sf::Texture\u0026 texture);\nImGui::ImageButton(const sf::RenderTexture\u0026 texture);\n```\n\nA note about sf::RenderTexture\n---\n\n`sf::RenderTexture`'s texture is stored with pixels flipped upside down. To display it properly when drawing `ImGui::Image` or `ImGui::ImageButton`, use overloads for `sf::RenderTexture`:\n\n```cpp\nsf::RenderTexture texture;\nsf::Sprite sprite(texture.getTexture());\nImGui::Image(texture);              // OK\nImGui::Image(sprite);               // NOT OK\nImGui::Image(texture.getTexture()); // NOT OK\n```\n\nIf you want to draw only a part of `sf::RenderTexture` and you're trying to use `sf::Sprite` the texture will be displayed upside-down. To prevent this, you can do this:\n\n```cpp\n// make a normal sf::Texture from sf::RenderTexture's flipped texture\nsf::Texture texture(renderTexture.getTexture());\n\nsf::Sprite sprite(texture);\nImGui::Image(sprite); // the texture is displayed properly\n```\n\nFor more notes see [this issue](https://github.com/SFML/imgui-sfml/issues/35).\n\nMouse cursors\n---\nYou can change your cursors in ImGui like this:\n\n```cpp\nImGui::SetMouseCursor(ImGuiMouseCursor_TextInput);\n```\n\nBy default, your system cursor will change and will be rendered by your system. If you want SFML to draw your cursor with default ImGui cursors (the system cursor will be hidden), do this:\n\n```cpp\nImGuiIO\u0026 io = ImGui::GetIO();\nio.MouseDrawCursor = true;\n```\n\nKeyboard/Gamepad navigation\n---\nStarting with [ImGui 1.60](https://github.com/ocornut/imgui/releases/tag/v1.60), there's a feature to control ImGui with keyboard and gamepad. To use keyboard navigation, you just need to do this:\n\n```cpp\nImGuiIO\u0026 io = ImGui::GetIO();\nio.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;\n```\n\nGamepad navigation requires more work, unless you have XInput gamepad, in which case the mapping is automatically set for you. But you can still set it up for your own gamepad easily, just take a look how it's done for the default mapping [here](https://github.com/SFML/imgui-sfml/blob/navigation/imgui-SFML.cpp#L697). And then you need to do this:\n\n```cpp\nImGuiIO\u0026 io = ImGui::GetIO();\nio.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad;\n```\nBy default, the first active joystick is used for navigation, but you can set joystick id explicitly like this:\n```cpp\nImGui::SFML::SetActiveJoystickId(5);\n```\n\nHigh DPI screens\n----\n\nAs SFML is not currently DPI aware, your GUI may show at the incorrect scale. This is particularly noticeable on systems with \"Retina\" / \"4K\" / \"UHD\" displays.\n\nTo work around this on macOS, you can create an app bundle (as opposed to just the exe) then modify the info.plist so that \"High Resolution Capable\" is set to \"NO\".\n\nAnother option to help ameliorate this, at least for getting started and for the common ImGui use-case of \"developer/debug/building UI\", is to explore `FontGlobalScale`:\n\n```cpp\nImGuiIO\u0026 io = ImGui::GetIO();\nio.FontGlobalScale = 2.0; // or any other value hardcoded or loaded from your config logic\n```\n\nLicense\n---\n\nThis library is licensed under the MIT License, see LICENSE for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsfml%2Fimgui-sfml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsfml%2Fimgui-sfml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsfml%2Fimgui-sfml/lists"}