Skip to content

Commit

Permalink
Demonstrate how to acquire and use ImGui-SFML
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisThrasher committed Aug 29, 2024
1 parent ed067a2 commit f73fc3e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
21 changes: 20 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)

include(FetchContent)

FetchContent_Declare(SFML
GIT_REPOSITORY https://github.com/SFML/SFML.git
GIT_TAG 2.6.x
Expand All @@ -13,8 +14,26 @@ FetchContent_Declare(SFML
SYSTEM)
FetchContent_MakeAvailable(SFML)

FetchContent_Declare(ImGui
GIT_REPOSITORY https://github.com/ocornut/imgui
GIT_TAG v1.89.9
GIT_SHALLOW ON
EXCLUDE_FROM_ALL
SYSTEM)
FetchContent_MakeAvailable(ImGui)
FetchContent_GetProperties(ImGui SOURCE_DIR IMGUI_DIR)

set(IMGUI_SFML_FIND_SFML OFF)
FetchContent_Declare(ImGui-SFML
GIT_REPOSITORY https://github.com/SFML/imgui-sfml
GIT_TAG 2.6.x
GIT_SHALLOW ON
EXCLUDE_FROM_ALL
SYSTEM)
FetchContent_MakeAvailable(ImGui-SFML)

add_executable(main src/main.cpp)
target_link_libraries(main PRIVATE sfml-graphics)
target_link_libraries(main PRIVATE sfml-graphics ImGui-SFML::ImGui-SFML)
target_compile_features(main PRIVATE cxx_std_17)

if(WIN32)
Expand Down
16 changes: 16 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,37 @@
#include <SFML/Graphics.hpp>
#include <imgui-SFML.h>
#include <imgui.h>

int main()
{
auto window = sf::RenderWindow{ { 1920u, 1080u }, "CMake SFML Project" };
window.setFramerateLimit(144);
if (!ImGui::SFML::Init(window))
return -1;

sf::Clock clock;
while (window.isOpen())
{
for (auto event = sf::Event{}; window.pollEvent(event);)
{
ImGui::SFML::ProcessEvent(window, event);

if (event.type == sf::Event::Closed)
{
window.close();
}
}

ImGui::SFML::Update(window, clock.restart());

ImGui::Begin("Hello, world!");
ImGui::Button("Look at this pretty button");
ImGui::End();

window.clear();
ImGui::SFML::Render(window);
window.display();
}

ImGui::SFML::Shutdown();
}

0 comments on commit f73fc3e

Please sign in to comment.