Open
Description
Hi, the following code used to work using SFML 2.6 but an exception was thrown after updating to v3.0.
OS: Windows 11
Microsoft Visual Studio Community 2022 (64-bit) - Preview
Version 17.14.0 Preview 1.1
> vcpkg version
vcpkg package management program version 2025-02-11-bec4296bf5289dc9ce83b4f5095943e44162f9c2
imgui-sfml:x64-windows 3.0
imgui:x64-windows 1.91.8#4
sfml:x64-windows 3.0.0
// main.cpp
// https://github.com/SFML/imgui-sfml/blob/master/examples/multiple_windows/main.cpp
#include "imgui.h" // necessary for ImGui::*, imgui-SFML.h doesn't include imgui.h
#include "imgui-SFML.h" // for ImGui::SFML::* functions and SFML-specific overloads
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode({ 1280, 720 }), "ImGui + SFML = <3");
window.setFramerateLimit(60);
if (!ImGui::SFML::Init(window))
return -1;
sf::RenderWindow childWindow(sf::VideoMode({ 640, 480 }), "ImGui-SFML Child window");
childWindow.setFramerateLimit(60);
if (!ImGui::SFML::Init(childWindow))
return -1;
sf::Clock deltaClock;
while (window.isOpen())
{
// Main window event processing
while (const auto event = window.pollEvent())
{
ImGui::SFML::ProcessEvent(window, *event);
if (event->is<sf::Event::Closed>())
{
if (childWindow.isOpen())
{
childWindow.close();
}
window.close();
ImGui::SFML::Shutdown(); // will shutdown all windows
return 0; // return here so that we don't call Update/Render
}
}
// Child window event processing
if (childWindow.isOpen())
{
while (const auto event = childWindow.pollEvent())
{
ImGui::SFML::ProcessEvent(childWindow, *event);
if (event->is<sf::Event::Closed>())
{
childWindow.close();
ImGui::SFML::Shutdown(childWindow);
}
}
}
// Update
const sf::Time dt = deltaClock.restart();
ImGui::SFML::Update(window, dt);
if (childWindow.isOpen())
{
ImGui::SFML::Update(childWindow, dt);
}
// Add ImGui widgets in the first window
ImGui::SFML::SetCurrentWindow(window);
ImGui::Begin("Hello, world!");
ImGui::Button("Look at this pretty button");
ImGui::End();
ImGui::ShowDemoWindow();
// Add ImGui widgets in the child window
if (childWindow.isOpen())
{
ImGui::SFML::SetCurrentWindow(childWindow);
ImGui::Begin("Works in a second window!");
ImGui::Button("Example button");
ImGui::End();
}
// Main window drawing
sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::Green);
window.clear();
window.draw(shape);
ImGui::SFML::Render(window);
window.display();
// Child window drawing
if (childWindow.isOpen())
{
sf::CircleShape shape2(50.f);
shape2.setFillColor(sf::Color::Red);
childWindow.clear();
childWindow.draw(shape2);
ImGui::SFML::Render(childWindow);
childWindow.display();
}
}
}
Metadata
Metadata
Assignees
Labels
No labels