Replace GLFW with SDL3
Since I plan to use SDL3 API, I had to replace GLFW window and surface creation with SDL3 variant. For now it's working fine.
This commit is contained in:
1 parent
393b59ad5d
commit
1b5cc7a79c
9 files changed
+43
-91
No files matched your search
+25
-73
@@ -10,8 +10,15 @@
|
||||
*/
|
||||
|
||||
#include "window.h"
|
||||
#include <SDL3/SDL_events.h>
|
||||
#include <SDL3/SDL_init.h>
|
||||
#include <SDL3/SDL_video.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#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();
|
||||
}
|
||||
Reference in new issue
Block a user