Skip to content

Commit e16ceb9

Browse files
committed
Demonstrate how to acquire and use ImGui-SFML
1 parent d778d7f commit e16ceb9

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

CMakeLists.txt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,23 @@ FetchContent_Declare(SFML
1111
EXCLUDE_FROM_ALL
1212
SYSTEM)
1313
FetchContent_MakeAvailable(SFML)
14+
FetchContent_Declare(ImGui
15+
GIT_REPOSITORY https://github.com/ocornut/imgui
16+
GIT_TAG v1.91.1
17+
GIT_SHALLOW ON
18+
EXCLUDE_FROM_ALL
19+
SYSTEM)
20+
FetchContent_MakeAvailable(ImGui)
21+
FetchContent_GetProperties(ImGui SOURCE_DIR IMGUI_DIR)
22+
set(IMGUI_SFML_FIND_SFML OFF)
23+
FetchContent_Declare(ImGui-SFML
24+
GIT_REPOSITORY https://github.com/SFML/imgui-sfml
25+
GIT_TAG v3.0
26+
GIT_SHALLOW ON
27+
EXCLUDE_FROM_ALL
28+
SYSTEM)
29+
FetchContent_MakeAvailable(ImGui-SFML)
1430

1531
add_executable(main src/main.cpp)
1632
target_compile_features(main PRIVATE cxx_std_17)
17-
target_link_libraries(main PRIVATE SFML::Graphics)
33+
target_link_libraries(main PRIVATE SFML::Graphics ImGui-SFML::ImGui-SFML)

src/main.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,37 @@
11
#include <SFML/Graphics.hpp>
2+
#include <imgui-SFML.h>
3+
#include <imgui.h>
24

35
int main()
46
{
57
auto window = sf::RenderWindow(sf::VideoMode({1920u, 1080u}), "CMake SFML Project");
68
window.setFramerateLimit(144);
9+
if (!ImGui::SFML::Init(window))
10+
return -1;
711

12+
sf::Clock clock;
813
while (window.isOpen())
914
{
1015
while (const std::optional event = window.pollEvent())
1116
{
17+
ImGui::SFML::ProcessEvent(window, *event);
18+
1219
if (event->is<sf::Event::Closed>())
1320
{
1421
window.close();
1522
}
1623
}
1724

25+
ImGui::SFML::Update(window, clock.restart());
26+
27+
ImGui::Begin("Hello, world!");
28+
ImGui::Button("Look at this pretty button");
29+
ImGui::End();
30+
1831
window.clear();
32+
ImGui::SFML::Render(window);
1933
window.display();
2034
}
35+
36+
ImGui::SFML::Shutdown();
2137
}

0 commit comments

Comments
 (0)