diff --git a/conanfile.txt b/conanfile.txt index 0a620f0d..52bcb8f2 100644 --- a/conanfile.txt +++ b/conanfile.txt @@ -2,7 +2,6 @@ vulkan-headers/1.4.309.0 vulkan-loader/1.4.309.0 libgettext/0.22 -glfw/3.4 freetype/2.13.3 stb/cci.20240531 sdl/3.2.14 diff --git a/graphics/CMakeLists.txt b/graphics/CMakeLists.txt index 31ab8eb7..375f7f2d 100644 --- a/graphics/CMakeLists.txt +++ b/graphics/CMakeLists.txt @@ -1,7 +1,6 @@ find_package(VulkanHeaders REQUIRED) find_package(VulkanLoader REQUIRED) # find_package(vulkan-validationlayers) -find_package(glfw3 REQUIRED) find_package(freetype REQUIRED) find_package(stb REQUIRED) find_package(SDL3 REQUIRED) @@ -42,7 +41,6 @@ target_link_libraries(graphics PUBLIC vulkan-headers::vulkan-headers Vulkan::Loader # vulkan-validationlayers::vulkan-validationlayers - glfw Freetype::Freetype stb::stb sdl::sdl diff --git a/graphics/src/graphics_context.h b/graphics/src/graphics_context.h index c72f3901..4fcba758 100644 --- a/graphics/src/graphics_context.h +++ b/graphics/src/graphics_context.h @@ -12,7 +12,7 @@ #ifndef GRAPHICS_CONTEXT_H #define GRAPHICS_CONTEXT_H -#include +#include "SDL3/SDL.h" #include #include #include @@ -93,7 +93,7 @@ struct pipeline_internal_t struct graphics_context_t { - GLFWwindow* window_handle; + SDL_Window* window_handle; VkDevice device; VkSurfaceKHR surface; VkInstance instance; diff --git a/graphics/src/vulkan_base.c b/graphics/src/vulkan_base.c index f504f05b..21aba44c 100644 --- a/graphics/src/vulkan_base.c +++ b/graphics/src/vulkan_base.c @@ -11,8 +11,9 @@ #include "vulkan_base.h" -#include -#include "utilities/localization.h" +#include +#include +#include #include #include "utilities/commons.h" @@ -171,7 +172,7 @@ static rse_err_t create_instance(VkInstance* instance) #ifdef WAYLAND "VK_KHR_wayland_surface", #else - "VK_KHR_xcb_surface", + "VK_KHR_xlib_surface", #endif /* WAYLAND */ #elif defined(_WIN32) || defined(WIN32) "VK_KHR_win32_surface", @@ -274,10 +275,10 @@ static rse_err_t create_instance(VkInstance* instance) * * @return rse_err_t RSE_ERROR_NO_ERROR on success. Possible errors: */ -static rse_err_t create_surface(VkInstance instance, GLFWwindow* window_handle, VkSurfaceKHR* surface) +static rse_err_t create_surface(VkInstance instance, SDL_Window* window_handle, VkSurfaceKHR* surface) { - if (VK_SUCCESS != glfwCreateWindowSurface(instance, window_handle, NULL, surface)) { - LOGF(_("Failed to create window surface\n")); + if (true != SDL_Vulkan_CreateSurface(window_handle, instance, NULL, surface)) { + LOGF(_("Failed to create window surface. Error: %s\n"), SDL_GetError()); return VULKAN_ERROR_SURFACE_CREATION_FAILED; } return RSE_ERROR_NO_ERROR; diff --git a/graphics/src/vulkan_swapchain.c b/graphics/src/vulkan_swapchain.c index ab93bd89..1ad18d66 100644 --- a/graphics/src/vulkan_swapchain.c +++ b/graphics/src/vulkan_swapchain.c @@ -1,3 +1,4 @@ +#include #include #include @@ -157,13 +158,14 @@ static rse_err_t create_framebuffers(struct graphics_context_t* context) */ void recreate_swapchain(struct graphics_context_t* context) { + SDL_Event event; int width = 0; int height = 0; - glfwGetFramebufferSize(context->window_handle, &width, &height); + SDL_GetWindowSizeInPixels(context->window_handle, &width, &height); while (width == 0 || height == 0) { - glfwGetFramebufferSize(context->window_handle, &width, &height); - glfwWaitEvents(); + SDL_GetWindowSizeInPixels(context->window_handle, &width, &height); + SDL_WaitEvent(&event); } vkDeviceWaitIdle(context->device); diff --git a/graphics/src/window.c b/graphics/src/window.c index f118c5ec..986ad603 100644 --- a/graphics/src/window.c +++ b/graphics/src/window.c @@ -10,8 +10,15 @@ */ #include "window.h" +#include +#include +#include +#include -#include "GLFW/glfw3.h" +#include "SDL3/SDL.h" +#include "SDL3/SDL_main.h" + +#include "utilities/commons.h" #include "utilities/localization.h" #include "window_errors.h" #include "utilities/logger.h" @@ -19,88 +26,32 @@ #include "vulkan/vulkan_core.h" #include "vulkan_base.h" -/** - * @brief GLFW error callback - * - * @param error Error code - * @param description Error description - */ -static void error_callback(int error, const char* description) +rse_err_t window_init(SDL_Window **window_handle, bool *is_framebuffer_resized) { - (void)error; - LOGE("Error: %s", description); -} + SDL_Init(SDL_INIT_VIDEO); -/** - * @brief Pressed key callback - * - * @param window Window in which contex the key has been pressed - * @param key The keyboard key that was pressed or released - * @param scancode The system-specific scancode of the key. - * @param action GLFW_PRESS, GLFW_RELEASE or GLFW_REPEAT - * @param mods Bit field describing which modifier keys were held down - */ -static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) -{ - (void)scancode; - (void)action; - (void)mods; - - if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) { - glfwSetWindowShouldClose(window, GLFW_TRUE); - } -} - -static void framebuffer_resized_callback(GLFWwindow* window, int width, int height) -{ - bool* is_frambuffer_resized = (bool*)glfwGetWindowUserPointer(window); - (void)window; - (void)width; - (void)height; - *is_frambuffer_resized = 1; -} - - -rse_err_t window_init(GLFWwindow** window_handle, bool* is_framebuffer_resized) -{ - /* Initiliaze GLFW AP */ - if (GLFW_TRUE != glfwInit()) - { - LOGF(_("GLFW init failed!\n")); - return WINDOW_ERROR_GLFW_INIT_FAILED; - } - - - /* Check for Vulkan support */ - if (GLFW_FALSE == glfwVulkanSupported()) { - LOGF(_("Unable to load Vulkan\n")); - return WINDOW_ERROR_VULKAN_NOT_LOADED; - } - - /* Set error callback */ - glfwSetErrorCallback(error_callback); - - /* Create window */ - glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); - - *window_handle = glfwCreateWindow(640, 480, "RedScarfEngine", NULL, NULL); + *window_handle = SDL_CreateWindow("RedScarfEngine", 640, 480, SDL_WINDOW_VULKAN); if (NULL == *window_handle) { LOGF(_("Window context creation failed\n")); return WINDOW_ERROR_WINDOW_NOT_CREATED; } - glfwSetKeyCallback(*window_handle, key_callback); - glfwSetFramebufferSizeCallback(*window_handle, framebuffer_resized_callback); - glfwSetWindowUserPointer(*window_handle, is_framebuffer_resized); - return RSE_ERROR_NO_ERROR; } rse_err_t window_loop(struct graphics_context_t* context) { - while (!glfwWindowShouldClose(context->window_handle)) { - glfwPollEvents(); + uint8_t done = 0; + SDL_Event event; + + while (0 == done) { + while (SDL_PollEvent(&event)) { + if (SDL_EVENT_QUIT == event.type) { + done = 1; + } + } + draw_frame(context); } @@ -108,8 +59,9 @@ rse_err_t window_loop(struct graphics_context_t* context) return RSE_ERROR_NO_ERROR; } -void window_terminate(GLFWwindow* window_handle) +void window_terminate(SDL_Window* window_handle) { - glfwDestroyWindow(window_handle); - glfwTerminate(); + SDL_DestroyWindow(window_handle); + + SDL_Quit(); } diff --git a/graphics/src/window.h b/graphics/src/window.h index 2529d9c1..d7ee9499 100644 --- a/graphics/src/window.h +++ b/graphics/src/window.h @@ -12,10 +12,10 @@ #ifndef WINDOW_H #define WINDOW_H +#include #include /* Vulkan header MUST be included before glfw */ -#include #include "utilities/commons.h" #include "graphics_context.h" @@ -30,7 +30,7 @@ * WINDOW_WINDOW_NOT_CREATED * */ -rse_err_t window_init(GLFWwindow** window_handle, bool* is_framebuffer_resized); +rse_err_t window_init(SDL_Window **window_handle, bool *is_framebuffer_resized); /** * @brief Main window loop @@ -45,6 +45,6 @@ rse_err_t window_loop(struct graphics_context_t* context); * * @param window_handle Pointer to window window_handle */ -void window_terminate(GLFWwindow* window_handle); +void window_terminate(SDL_Window* window_handle); #endif /* WINDOW_H */ diff --git a/red_scarf_engine/src/main.c b/red_scarf_engine/src/main.c index 2bcbeaf4..86de0185 100644 --- a/red_scarf_engine/src/main.c +++ b/red_scarf_engine/src/main.c @@ -1,6 +1,5 @@ #include "graphics/rse_graphics.h" #include "utilities/errors_common.h" -#include "utilities/localization.h" #include "utilities/logger.h" #include "SDL3/SDL_thread.h" diff --git a/utilities/logger.h b/utilities/logger.h index 7b35fd11..f1e476c9 100644 --- a/utilities/logger.h +++ b/utilities/logger.h @@ -12,6 +12,7 @@ #ifndef LOGGER_H #define LOGGER_H +#include "utilities/localization.h" #include #include