Skip to content

Commit 6f900d0

Browse files
committed
Demonstrate how to acquire and use ImGui-SFML
1 parent 0d7dd8d commit 6f900d0

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

CMakeLists.txt

+20-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ project(CMakeSFMLProject LANGUAGES CXX)
44
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
55

66
include(FetchContent)
7+
78
FetchContent_Declare(SFML
89
GIT_REPOSITORY https://github.com/SFML/SFML.git
910
GIT_TAG 3.0.0
@@ -12,5 +13,23 @@ FetchContent_Declare(SFML
1213
SYSTEM)
1314
FetchContent_MakeAvailable(SFML)
1415

16+
FetchContent_Declare(ImGui
17+
GIT_REPOSITORY https://github.com/ocornut/imgui
18+
GIT_TAG v1.91.1
19+
GIT_SHALLOW ON
20+
EXCLUDE_FROM_ALL
21+
SYSTEM)
22+
FetchContent_MakeAvailable(ImGui)
23+
FetchContent_GetProperties(ImGui SOURCE_DIR IMGUI_DIR)
24+
25+
set(IMGUI_SFML_FIND_SFML OFF)
26+
FetchContent_Declare(ImGui-SFML
27+
GIT_REPOSITORY https://github.com/SFML/imgui-sfml
28+
GIT_TAG v3.0
29+
GIT_SHALLOW ON
30+
EXCLUDE_FROM_ALL
31+
SYSTEM)
32+
FetchContent_MakeAvailable(ImGui-SFML)
33+
1534
add_executable(main src/main.cpp)
16-
target_link_libraries(main PRIVATE SFML::Graphics)
35+
target_link_libraries(main PRIVATE SFML::Graphics ImGui-SFML::ImGui-SFML)

src/main.cpp

+16
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)