Skip to content

Commit 3b1aff7

Browse files
committed
Demonstrate how to acquire and use ImGui-SFML
1 parent 1faab78 commit 3b1aff7

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

CMakeLists.txt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,26 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
55
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
66

77
include(FetchContent)
8+
89
FetchContent_Declare(SFML
910
GIT_REPOSITORY https://github.com/SFML/SFML.git
1011
GIT_TAG 2.6.x)
1112
FetchContent_MakeAvailable(SFML)
1213

14+
FetchContent_Declare(ImGui
15+
GIT_REPOSITORY https://github.com/ocornut/imgui
16+
GIT_TAG v1.89.9)
17+
FetchContent_MakeAvailable(ImGui)
18+
FetchContent_GetProperties(ImGui SOURCE_DIR IMGUI_DIR)
19+
20+
set(IMGUI_SFML_FIND_SFML OFF)
21+
FetchContent_Declare(ImGui-SFML
22+
GIT_REPOSITORY https://github.com/SFML/imgui-sfml
23+
GIT_TAG 2.6.x)
24+
FetchContent_MakeAvailable(ImGui-SFML)
25+
1326
add_executable(CMakeSFMLProject src/main.cpp)
14-
target_link_libraries(CMakeSFMLProject PRIVATE sfml-graphics)
27+
target_link_libraries(CMakeSFMLProject PRIVATE sfml-graphics ImGui-SFML::ImGui-SFML)
1528
target_compile_features(CMakeSFMLProject PRIVATE cxx_std_17)
1629

1730
if(WIN32)

src/main.cpp

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

35
int main()
46
{
5-
auto window = sf::RenderWindow{ { 1920u, 1080u }, "CMake SFML Project" };
7+
auto window = sf::RenderWindow{ { 1280u, 720u }, "CMake SFML Project" };
68
window.setFramerateLimit(144);
9+
ImGui::SFML::Init(window);
710

11+
sf::Clock clock;
812
while (window.isOpen())
913
{
1014
for (auto event = sf::Event{}; window.pollEvent(event);)
1115
{
16+
ImGui::SFML::ProcessEvent(window, event);
17+
1218
if (event.type == sf::Event::Closed)
1319
{
1420
window.close();
1521
}
1622
}
1723

24+
ImGui::SFML::Update(window, clock.restart());
25+
26+
ImGui::Begin("Hello, world!");
27+
ImGui::Button("Look at this pretty button");
28+
ImGui::End();
29+
1830
window.clear();
31+
ImGui::SFML::Render(window);
1932
window.display();
2033
}
21-
}
34+
35+
ImGui::SFML::Shutdown();
36+
}

0 commit comments

Comments
 (0)