diff --git a/.gitignore b/.gitignore index 26837de..f3a3ed0 100644 --- a/.gitignore +++ b/.gitignore @@ -103,4 +103,7 @@ CMakeUserPresets.json # Other .cache/ .vscode/ -build/ \ No newline at end of file +build/ + +.kdev4/ +*.kdev4 diff --git a/CMakeLists.txt b/CMakeLists.txt index 54c2c86..38741c4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,10 +1,10 @@ cmake_minimum_required(VERSION 3.10) -project(vksdlproj VERSION 0.1.0 LANGUAGES C CXX) +project(vksdlproj VERSION 0.2.0 LANGUAGES C CXX) SET(CMAKE_BUILD_RPATH_USE_ORIGIN TRUE) set(EXE_NAME project) -set(PROGRAM_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/vulkanapp.cc) +set(PROGRAM_SOURCES )#${CMAKE_CURRENT_SOURCE_DIR}/src/vulkanapp.cc) option(SDL3_NONSYSTEM "Use SDL3 from folder in source tree" ON) @@ -69,4 +69,4 @@ endif() # Linking target_link_libraries(${EXE_NAME} PRIVATE SDL3::SDL3) target_link_libraries(${EXE_NAME} PRIVATE Vulkan::Vulkan) -target_link_libraries(${EXE_NAME} PRIVATE vk-bootstrap::vk-bootstrap) \ No newline at end of file +target_link_libraries(${EXE_NAME} PRIVATE vk-bootstrap::vk-bootstrap) diff --git a/include/vulkanapp.hh b/include/vulkanapp.hh index 76d0c52..c8b962f 100644 --- a/include/vulkanapp.hh +++ b/include/vulkanapp.hh @@ -7,6 +7,8 @@ #include #include +#include + #include const std::vector validationLayers = { @@ -138,4 +140,4 @@ private: return VK_FALSE; } -}; \ No newline at end of file +}; diff --git a/src/main.cc b/src/main.cc index 68402ec..3f31460 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,19 +1,62 @@ -#include "vulkanapp.hh" +#define SDL_MAIN_USE_CALLBACKS +#include +#include +#include -#include +constexpr uint32_t winInitWidth = 512; +constexpr uint32_t winInitHeight = 512; -int main() { - VulkanApp app(1024, 1024); +struct AppContext { + SDL_Window *window; + SDL_AppResult appQuit = SDL_APP_CONTINUE; +}; - try { - app.init(); - app.loop(); - app.cleanup(); - } catch(const std::exception& except) { - fprintf(stderr, "Error! %s\n", except.what()); +SDL_AppResult SDL_Fail() { + SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Error: %s", SDL_GetError()); + return SDL_APP_FAILURE; +} - return 1; +SDL_AppResult SDL_AppInit(void **appstate, int argc, char **argv) { + if(!SDL_Init(SDL_INIT_VIDEO)) + return SDL_Fail(); + + SDL_Window *win = SDL_CreateWindow("SDL3 Vulkan", winInitWidth, winInitHeight, SDL_WINDOW_RESIZABLE | SDL_WINDOW_VULKAN); + + if(!win) + return SDL_Fail(); + + *appstate = new AppContext { + .window = win, + }; + + return SDL_APP_CONTINUE; +} + +SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event) { + AppContext* app = static_cast(appstate); + + switch(event->type) { + case SDL_EVENT_QUIT: + app->appQuit = SDL_APP_SUCCESS; } - return 0; -} \ No newline at end of file + return SDL_APP_CONTINUE; +} + +SDL_AppResult SDL_AppIterate(void *appstate) { + AppContext* app = static_cast(appstate); + + return app->appQuit; +} + +void SDL_AppQuit(void *appstate, SDL_AppResult result) { + AppContext* app = static_cast(appstate); + + if(app) { + SDL_DestroyWindow(app->window); + + delete app; + } + + SDL_Quit(); +}