commit d318b72c3b486f0fcd9b2f71206551b1a4fcf085 Author: HKU Aaron Account Date: Thu Aug 28 14:52:41 2025 +0200 Starting repo diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e0900a6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# Ignore all files in any directory named build +build/ \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..280cf11 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 3.28) + +project(low-level_setup + VERSION 1.0 + LANGUAGES CXX +) + +add_subdirectory(dependencies) +add_subdirectory(src) \ No newline at end of file diff --git a/dependencies/CMakeLists.txt b/dependencies/CMakeLists.txt new file mode 100644 index 0000000..54fefe3 --- /dev/null +++ b/dependencies/CMakeLists.txt @@ -0,0 +1,48 @@ +include(FetchContent) + +set(SFML_VERSION 3.0.0) +set(IMGUI_VERSION 1.91.1) + +option(LINK_DEPS_STATIC CACHE ON) + +# Don't build shared libs if we want to link to deps statically +if(LINK_DEPS_STATIC) + set(BUILD_SHARED_LIBS OFF) +else() + set(BUILD_SHARED_LIBS ON) +endif() + +# Get stripped down release zips +FetchContent_Declare( + SFML + URL "https://github.com/SFML/SFML/archive/${SFML_VERSION}.zip" +) + +FetchContent_Declare( + imgui + URL "https://github.com/ocornut/imgui/archive/v${IMGUI_VERSION}.zip" +) + +# imgui_sfml full repo +FetchContent_Declare( + imgui-sfml + GIT_REPOSITORY https://github.com/SFML/imgui-sfml.git + GIT_TAG v3.0 +) + +# BUILDING + +# SFML +option(SFML_BUILD_AUDIO "Build audio" OFF) +option(SFML_BUILD_NETWORK "Build network" OFF) +FetchContent_MakeAvailable(sfml) + +# IMGUI +FetchContent_MakeAvailable(imgui) + +# IMGUI-SFML +set(IMGUI_DIR ${imgui_SOURCE_DIR}) +option(IMGUI_SFML_FIND_SFML "Use find_package to find SFML" OFF) +option(IMGUI_SFML_IMGUI_DEMO "Build imgui_demo.cpp" ON) + +FetchContent_MakeAvailable(imgui-sfml) \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..3bbd949 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,11 @@ +add_executable(low-level_setup + main.cpp +) + +target_link_libraries(low-level_setup + PUBLIC + ImGui-SFML::ImGui-SFML +) + +# Do we need this? +# include(Install.cmake) \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..08c43d7 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,43 @@ +#include "imgui.h" +#include "imgui-SFML.h" + +#include + +int main() { + sf::RenderWindow window; + window.create(sf::VideoMode({ 1280, 720 }), "My window"); + window.setFramerateLimit(60); + window.setVerticalSyncEnabled(true); + + if (!ImGui::SFML::Init(window)) + return -1; + + sf::Clock deltaClock; + while (window.isOpen()) + { + float deltaTime = deltaClock.restart().asSeconds(); + + // Event Polling + while (const std::optional event = window.pollEvent()) + { + ImGui::SFML::ProcessEvent(window, *event); + + // "close requested" event: we close the window + if (event->is()) + window.close(); + } + + // Update + ImGui::SFML::Update(window, deltaClock.restart()); + // ImGui::ShowDemoWindow(); + + // Render + window.clear(); + + ImGui::SFML::Render(window); + + window.display(); + } + + return 0; +} \ No newline at end of file