Skip to content

Commit cccf2cd

Browse files
committed
Demonstrate how to acquire and use ImGui-SFML
1 parent 2163ac3 commit cccf2cd

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

CMakeLists.txt

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ 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
@@ -13,8 +14,26 @@ FetchContent_Declare(SFML
1314
SYSTEM)
1415
FetchContent_MakeAvailable(SFML)
1516

17+
FetchContent_Declare(ImGui
18+
GIT_REPOSITORY https://github.com/ocornut/imgui
19+
GIT_TAG v1.89.9
20+
GIT_SHALLOW ON
21+
EXCLUDE_FROM_ALL
22+
SYSTEM)
23+
FetchContent_MakeAvailable(ImGui)
24+
FetchContent_GetProperties(ImGui SOURCE_DIR IMGUI_DIR)
25+
26+
set(IMGUI_SFML_FIND_SFML OFF)
27+
FetchContent_Declare(ImGui-SFML
28+
GIT_REPOSITORY https://github.com/SFML/imgui-sfml
29+
GIT_TAG 2.6.x
30+
GIT_SHALLOW ON
31+
EXCLUDE_FROM_ALL
32+
SYSTEM)
33+
FetchContent_MakeAvailable(ImGui-SFML)
34+
1635
add_executable(main src/main.cpp)
17-
target_link_libraries(main PRIVATE sfml-graphics)
36+
target_link_libraries(main PRIVATE sfml-graphics ImGui-SFML::ImGui-SFML)
1837
target_compile_features(main PRIVATE cxx_std_17)
1938

2039
if(WIN32)

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({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
for (auto event = sf::Event(); window.pollEvent(event);)
1116
{
17+
ImGui::SFML::ProcessEvent(window, event);
18+
1219
if (event.type == 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)