From f03f521141d45581f529884cc2b8e87a875e4703 Mon Sep 17 00:00:00 2001 From: Bliblank Date: Sat, 11 Apr 2026 01:10:34 -0500 Subject: [PATCH] window creation --- CMakeLists.txt | 23 ++++++++++++++++++----- README.md | 2 +- src/app/App.cpp | 15 +++++++++++++++ src/app/App.hpp | 4 ++++ src/app/Window.cpp | 4 +++- src/app/Window.hpp | 3 ++- src/main.cpp | 2 -- 7 files changed, 43 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8b8b5d2..4ae0d5c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,24 +1,28 @@ -cmake_minimum_required(VERSION 3.2) +cmake_minimum_required(VERSION 3.10) project(ouros) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++20 -O3") + +if(MSVC) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /O2 /Oi /Ot /GT") +elseif(LINUX) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++20 -O3") +endif() set(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR}) #add_subdirectory(src) - -set(SDL3_DIR "C:/Users/pmcge/Downloads/SDL3-devel-3.4.4-VC/SDL3-3.4.4") - +set(SDL3_DIR "${SDL3_PATH}/cmake") find_package(SDL3 REQUIRED) # TODO: cascade cmakelists.txt add_executable(ouros src/main.cpp src/app/App.cpp + src/app/Window.cpp ) target_include_directories(ouros PRIVATE @@ -26,6 +30,15 @@ target_include_directories(ouros PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src" ) +if(WIN32) + set(SDL3_DLL "${SDL3_PATH}/lib/x64/SDL3.dll") # assuming youre not arm or 32 bit + add_custom_command(TARGET ouros POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + "${SDL3_DLL}" + $ + ) +endif() + target_link_libraries(ouros PRIVATE SDL3::SDL3 ) diff --git a/README.md b/README.md index c85c1dc..f8fc5a9 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ $ git clone https://git.vxbard.net/homeburger/ouros.git --recursive ``` ### Configure and build project: ```bash -$ cmake -S . -B build +$ cmake -S . -B build -DSDL3_PATH="${SDL3_INSTALL_PATH}" $ cmake --build build -j ``` ### Execute application: diff --git a/src/app/App.cpp b/src/app/App.cpp index d30dcdf..1f6b856 100644 --- a/src/app/App.cpp +++ b/src/app/App.cpp @@ -15,12 +15,27 @@ void App::init() { utils::debugPrint(__FUNCTION__, __LINE__, "Init app."); + window_ = new Window(); + } int App::run() { utils::debugPrint(__FUNCTION__, __LINE__, "Run app."); + bool quit = false; + while (!quit) { + // app loop for as long as the window is open + // poll events here + // other threads might be able to change quit to true to auto close + + while( SDL_PollEvent( &e ) != 0 ) { + if( e.type == SDL_QUIT ) { + // Ctrl + C in console ! + } + } + } + return 0; } diff --git a/src/app/App.hpp b/src/app/App.hpp index 9866754..e636213 100644 --- a/src/app/App.hpp +++ b/src/app/App.hpp @@ -1,6 +1,8 @@ #pragma once +#include "Window.hpp" + class App { public: @@ -16,4 +18,6 @@ private: // things like creating a window, creating the rendering engine, etc. void init(); + Window* window_; + }; \ No newline at end of file diff --git a/src/app/Window.cpp b/src/app/Window.cpp index 434ad03..bdcfebf 100644 --- a/src/app/Window.cpp +++ b/src/app/Window.cpp @@ -3,7 +3,7 @@ Window::Window() { - init(); + (void)init(); } @@ -11,4 +11,6 @@ int Window::init() { window_ = SDL_CreateWindow("How to Vulkan", 1280u, 720u, SDL_WINDOW_VULKAN | SDL_WINDOW_RESIZABLE); + return 0; + } diff --git a/src/app/Window.hpp b/src/app/Window.hpp index 605d5a0..ea5f48e 100644 --- a/src/app/Window.hpp +++ b/src/app/Window.hpp @@ -4,6 +4,8 @@ #include "SDL3/SDL.h" #include "SDL3/SDL_Vulkan.h" +// reference: https://wiki.libsdl.org/SDL3/SDL_CreateWindow + class Window { public: @@ -17,5 +19,4 @@ private: SDL_Window* window_; - }; \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index c176e1e..40b4577 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,8 +6,6 @@ int main(int arg, char *argv[]) { - std::cout << "[" << __FUNCTION__ << ": "<< __LINE__ << "] " << "main()" << std::endl; - std::string message = "main()"; utils::debugPrint(__FUNCTION__, __LINE__, message);