File tree Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ project(CMakeSFMLProject LANGUAGES CXX)
44set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} /bin)
55
66include (FetchContent)
7+
78FetchContent_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 )
1314FetchContent_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+
1534add_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 )
Original file line number Diff line number Diff line change 11#include < SFML/Graphics.hpp>
2+ #include < imgui-SFML.h>
3+ #include < imgui.h>
24
35int 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}
You can’t perform that action at this time.
0 commit comments