File tree 2 files changed +36
-1
lines changed
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)
4
4
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} /bin)
5
5
6
6
include (FetchContent)
7
+
7
8
FetchContent_Declare(SFML
8
9
GIT_REPOSITORY https://github.com/SFML/SFML.git
9
10
GIT_TAG 3.0.0
@@ -12,5 +13,23 @@ FetchContent_Declare(SFML
12
13
SYSTEM )
13
14
FetchContent_MakeAvailable(SFML)
14
15
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
+
15
34
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 )
Original file line number Diff line number Diff line change 1
1
#include < SFML/Graphics.hpp>
2
+ #include < imgui-SFML.h>
3
+ #include < imgui.h>
2
4
3
5
int main ()
4
6
{
5
7
auto window = sf::RenderWindow (sf::VideoMode ({1920u , 1080u }), " CMake SFML Project" );
6
8
window.setFramerateLimit (144 );
9
+ if (!ImGui::SFML::Init (window))
10
+ return -1 ;
7
11
12
+ sf::Clock clock ;
8
13
while (window.isOpen ())
9
14
{
10
15
while (const std::optional event = window.pollEvent ())
11
16
{
17
+ ImGui::SFML::ProcessEvent (window, *event);
18
+
12
19
if (event->is <sf::Event::Closed>())
13
20
{
14
21
window.close ();
15
22
}
16
23
}
17
24
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
+
18
31
window.clear ();
32
+ ImGui::SFML::Render (window);
19
33
window.display ();
20
34
}
35
+
36
+ ImGui::SFML::Shutdown ();
21
37
}
You can’t perform that action at this time.
0 commit comments