summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederico Linhares <fred@linhares.blue>2025-07-14 21:27:52 -0300
committerFrederico Linhares <fred@linhares.blue>2025-07-14 21:27:52 -0300
commit4c52564f56545796ec5d9c03c93276347d732034 (patch)
tree6c581ffa4122e33fe5cfbc65049c627a5e485f2d
parent8ef58d472533a43155893889dfb1f97a4dec2dcf (diff)
feat Update to SDL3
-rw-r--r--README.markdown2
-rw-r--r--Rakefile2
-rw-r--r--rake/windows.rake2
-rw-r--r--src/blu_cat/int/core.cpp24
-rw-r--r--src/blu_cat/int/core.hpp4
-rw-r--r--src/candy_gear/key.cpp54
-rw-r--r--src/candy_gear/main.cpp18
-rw-r--r--windows_installer.nsi2
8 files changed, 53 insertions, 55 deletions
diff --git a/README.markdown b/README.markdown
index 3e23118..692096f 100644
--- a/README.markdown
+++ b/README.markdown
@@ -11,7 +11,7 @@ However, because of this flexibility, the engine presumes that you have some bas
Installation
------------
-CandyGear uses the libraries libSDL2, Vulkan, and freetype, so before installing CandyGear into a machine, ensure that development libraries for SDL are installed.
+CandyGear uses the libraries libSDL3, Vulkan, and freetype, so before installing CandyGear into a machine, ensure that development libraries for SDL are installed.
CandyGear is compiled with Ruby Rake; also ensure it is installed.
To compile the code, run `rake` at the root directory; it will generate the binary engine.
To install the core, run `rake install`.
diff --git a/Rakefile b/Rakefile
index baf28fb..7a5ca8f 100644
--- a/Rakefile
+++ b/Rakefile
@@ -52,7 +52,7 @@ GLSL_FILES = FileList[
SPV_FILES = GLSL_FILES.ext('.spv')
LIBRARIES = [
- 'SDL2',
+ 'SDL3',
'freetype',
'm'
] + OS_LIBRARIES
diff --git a/rake/windows.rake b/rake/windows.rake
index 4c7c980..2b54967 100644
--- a/rake/windows.rake
+++ b/rake/windows.rake
@@ -13,7 +13,7 @@
# limitations under the License
OS_LIBRARIES = [
- 'SDL2main',
+ 'SDL3main',
'mingw32',
'vulkan-1.dll',
'ws2_32'
diff --git a/src/blu_cat/int/core.cpp b/src/blu_cat/int/core.cpp
index 5b9e53b..ffae1d2 100644
--- a/src/blu_cat/int/core.cpp
+++ b/src/blu_cat/int/core.cpp
@@ -56,14 +56,14 @@ vk_debug_callback(
void
load_sdl(void *obj)
{
- if(SDL_Init(SDL_INIT_EVERYTHING) < 0)
+ if(!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS))
{
std::string error{"SDL could not initialize! SDL Error → "};
error += SDL_GetError();
- throw error;
+ throw CommandError{error};
}
- if(SDL_Vulkan_LoadLibrary(nullptr) != 0)
+ if(!SDL_Vulkan_LoadLibrary(nullptr))
{
SDL_Quit();
std::string error{"SDL could not initialize Vulkan! SDL_Error → "};
@@ -82,13 +82,11 @@ unload_sdl(void *obj)
void
load_window(void *obj)
{
- BluCat::INT::core.window = nullptr;
BluCat::INT::core.window = SDL_CreateWindow(
BluCat::INT::core.game_name.c_str(),
- SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
BluCat::INT::core.display_width, BluCat::INT::core.display_height,
SDL_WINDOW_VULKAN);
- if(BluCat::INT::core.window == nullptr)
+ if(BluCat::INT::core.window == NULL)
{
std::string error{"Window could not be created! SDL_Error → "};
error += SDL_GetError();
@@ -124,8 +122,10 @@ load_vk_instance(void *obj)
uint32_t vk_sdl_extension_count;
std::vector<const char*> vk_sdl_extensions;
- if(!SDL_Vulkan_GetInstanceExtensions(
- BluCat::INT::core.window, &vk_sdl_extension_count, nullptr))
+ const char * const *instance_extensions =
+ SDL_Vulkan_GetInstanceExtensions(&vk_sdl_extension_count);
+
+ if(instance_extensions == NULL)
{
std::string error{
"Vulkan extensions could not be loaded by SDL! SDL_Error: "};
@@ -133,10 +133,8 @@ load_vk_instance(void *obj)
throw CommandError{error};
}
- vk_sdl_extensions.resize(vk_sdl_extension_count);
- SDL_Vulkan_GetInstanceExtensions(
- BluCat::INT::core.window, &vk_sdl_extension_count,
- vk_sdl_extensions.data());
+ for(auto i{0}; i < vk_sdl_extension_count; i++)
+ vk_sdl_extensions.push_back(instance_extensions[i]);
// Combine all extensions.
vk_extensions_count = vk_sdl_extension_count +
@@ -254,7 +252,7 @@ load_window_surface(void *obj)
{
if(!SDL_Vulkan_CreateSurface(
BluCat::INT::core.window, BluCat::INT::core.vk_instance,
- &BluCat::INT::core.window_surface))
+ nullptr, &BluCat::INT::core.window_surface))
{
std::string error{"Failed to create a window surface → "};
error += SDL_GetError();
diff --git a/src/blu_cat/int/core.hpp b/src/blu_cat/int/core.hpp
index c369e7b..0e5f3a3 100644
--- a/src/blu_cat/int/core.hpp
+++ b/src/blu_cat/int/core.hpp
@@ -32,8 +32,8 @@
#include <Windows.h>
#endif
-#include <SDL2/SDL.h>
-#include <SDL2/SDL_vulkan.h>
+#include <SDL3/SDL.h>
+#include <SDL3/SDL_vulkan.h>
#include <ft2build.h>
#include FT_FREETYPE_H
diff --git a/src/candy_gear/key.cpp b/src/candy_gear/key.cpp
index 615119c..74c2181 100644
--- a/src/candy_gear/key.cpp
+++ b/src/candy_gear/key.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2022 Frederico de Oliveira Linhares
+ * Copyright 2022-2025 Frederico de Oliveira Linhares
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,32 +24,32 @@ cg_key_init(mrb_state *mrb)
cg_m = mrb_module_get(mrb, "CandyGear");
cg_mKey = mrb_define_module_under(mrb, cg_m, "Key");
- mrb_define_const(mrb, cg_mKey, "A", mrb_int_value(mrb, SDLK_a));
- mrb_define_const(mrb, cg_mKey, "B", mrb_int_value(mrb, SDLK_b));
- mrb_define_const(mrb, cg_mKey, "C", mrb_int_value(mrb, SDLK_c));
- mrb_define_const(mrb, cg_mKey, "D", mrb_int_value(mrb, SDLK_d));
- mrb_define_const(mrb, cg_mKey, "E", mrb_int_value(mrb, SDLK_e));
- mrb_define_const(mrb, cg_mKey, "F", mrb_int_value(mrb, SDLK_f));
- mrb_define_const(mrb, cg_mKey, "G", mrb_int_value(mrb, SDLK_g));
- mrb_define_const(mrb, cg_mKey, "H", mrb_int_value(mrb, SDLK_h));
- mrb_define_const(mrb, cg_mKey, "I", mrb_int_value(mrb, SDLK_i));
- mrb_define_const(mrb, cg_mKey, "J", mrb_int_value(mrb, SDLK_j));
- mrb_define_const(mrb, cg_mKey, "K", mrb_int_value(mrb, SDLK_k));
- mrb_define_const(mrb, cg_mKey, "L", mrb_int_value(mrb, SDLK_l));
- mrb_define_const(mrb, cg_mKey, "M", mrb_int_value(mrb, SDLK_m));
- mrb_define_const(mrb, cg_mKey, "N", mrb_int_value(mrb, SDLK_n));
- mrb_define_const(mrb, cg_mKey, "O", mrb_int_value(mrb, SDLK_o));
- mrb_define_const(mrb, cg_mKey, "P", mrb_int_value(mrb, SDLK_p));
- mrb_define_const(mrb, cg_mKey, "Q", mrb_int_value(mrb, SDLK_q));
- mrb_define_const(mrb, cg_mKey, "R", mrb_int_value(mrb, SDLK_r));
- mrb_define_const(mrb, cg_mKey, "S", mrb_int_value(mrb, SDLK_s));
- mrb_define_const(mrb, cg_mKey, "T", mrb_int_value(mrb, SDLK_t));
- mrb_define_const(mrb, cg_mKey, "U", mrb_int_value(mrb, SDLK_u));
- mrb_define_const(mrb, cg_mKey, "V", mrb_int_value(mrb, SDLK_v));
- mrb_define_const(mrb, cg_mKey, "W", mrb_int_value(mrb, SDLK_w));
- mrb_define_const(mrb, cg_mKey, "X", mrb_int_value(mrb, SDLK_x));
- mrb_define_const(mrb, cg_mKey, "Y", mrb_int_value(mrb, SDLK_y));
- mrb_define_const(mrb, cg_mKey, "Z", mrb_int_value(mrb, SDLK_z));
+ mrb_define_const(mrb, cg_mKey, "A", mrb_int_value(mrb, SDLK_A));
+ mrb_define_const(mrb, cg_mKey, "B", mrb_int_value(mrb, SDLK_B));
+ mrb_define_const(mrb, cg_mKey, "C", mrb_int_value(mrb, SDLK_C));
+ mrb_define_const(mrb, cg_mKey, "D", mrb_int_value(mrb, SDLK_D));
+ mrb_define_const(mrb, cg_mKey, "E", mrb_int_value(mrb, SDLK_E));
+ mrb_define_const(mrb, cg_mKey, "F", mrb_int_value(mrb, SDLK_F));
+ mrb_define_const(mrb, cg_mKey, "G", mrb_int_value(mrb, SDLK_G));
+ mrb_define_const(mrb, cg_mKey, "H", mrb_int_value(mrb, SDLK_H));
+ mrb_define_const(mrb, cg_mKey, "I", mrb_int_value(mrb, SDLK_I));
+ mrb_define_const(mrb, cg_mKey, "J", mrb_int_value(mrb, SDLK_J));
+ mrb_define_const(mrb, cg_mKey, "K", mrb_int_value(mrb, SDLK_K));
+ mrb_define_const(mrb, cg_mKey, "L", mrb_int_value(mrb, SDLK_L));
+ mrb_define_const(mrb, cg_mKey, "M", mrb_int_value(mrb, SDLK_M));
+ mrb_define_const(mrb, cg_mKey, "N", mrb_int_value(mrb, SDLK_N));
+ mrb_define_const(mrb, cg_mKey, "O", mrb_int_value(mrb, SDLK_O));
+ mrb_define_const(mrb, cg_mKey, "P", mrb_int_value(mrb, SDLK_P));
+ mrb_define_const(mrb, cg_mKey, "Q", mrb_int_value(mrb, SDLK_Q));
+ mrb_define_const(mrb, cg_mKey, "R", mrb_int_value(mrb, SDLK_R));
+ mrb_define_const(mrb, cg_mKey, "S", mrb_int_value(mrb, SDLK_S));
+ mrb_define_const(mrb, cg_mKey, "T", mrb_int_value(mrb, SDLK_T));
+ mrb_define_const(mrb, cg_mKey, "U", mrb_int_value(mrb, SDLK_U));
+ mrb_define_const(mrb, cg_mKey, "V", mrb_int_value(mrb, SDLK_V));
+ mrb_define_const(mrb, cg_mKey, "W", mrb_int_value(mrb, SDLK_W));
+ mrb_define_const(mrb, cg_mKey, "X", mrb_int_value(mrb, SDLK_X));
+ mrb_define_const(mrb, cg_mKey, "Y", mrb_int_value(mrb, SDLK_Y));
+ mrb_define_const(mrb, cg_mKey, "Z", mrb_int_value(mrb, SDLK_Z));
mrb_define_const(mrb, cg_mKey, "UP", mrb_int_value(mrb, SDLK_UP));
mrb_define_const(mrb, cg_mKey, "DOWN", mrb_int_value(mrb, SDLK_DOWN));
diff --git a/src/candy_gear/main.cpp b/src/candy_gear/main.cpp
index 353b6bf..bc38e9e 100644
--- a/src/candy_gear/main.cpp
+++ b/src/candy_gear/main.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2022-2024 Frederico de Oliveira Linhares
+ * Copyright 2022-2025 Frederico de Oliveira Linhares
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -63,23 +63,23 @@ int main(int argc, char *argv[])
{
switch(event.type)
{
- case SDL_KEYDOWN:
+ case SDL_EVENT_KEY_DOWN:
mrb_funcall_id(
cg_core.mrb, main_obj, cg_core.sym_key_down, 1,
- mrb_int_value(cg_core.mrb, event.key.keysym.sym));
+ mrb_int_value(cg_core.mrb, event.key.key));
break;
- case SDL_KEYUP:
+ case SDL_EVENT_KEY_UP:
mrb_funcall_id(
cg_core.mrb, main_obj, cg_core.sym_key_up, 1,
- mrb_int_value(cg_core.mrb, event.key.keysym.sym));
+ mrb_int_value(cg_core.mrb, event.key.key));
break;
- case SDL_MOUSEMOTION:
+ case SDL_EVENT_MOUSE_MOTION:
break;
- case SDL_MOUSEBUTTONDOWN:
+ case SDL_EVENT_MOUSE_BUTTON_DOWN:
break;
- case SDL_MOUSEBUTTONUP:
+ case SDL_EVENT_MOUSE_BUTTON_UP:
break;
- case SDL_QUIT:
+ case SDL_EVENT_QUIT:
mrb_funcall_id(cg_core.mrb, main_obj, cg_core.sym_quit, 0);
break;
}
diff --git a/windows_installer.nsi b/windows_installer.nsi
index 5bb894c..09af12b 100644
--- a/windows_installer.nsi
+++ b/windows_installer.nsi
@@ -48,7 +48,7 @@ Section
File "$%DLL_PATH%\\libpng16-16.dll"
File "$%DLL_PATH%\\libstdc++-6.dll"
File "$%DLL_PATH%\\libwinpthread-1.dll"
- File "$%DLL_PATH%\\SDL2.dll"
+ File "$%DLL_PATH%\\SDL3.dll"
File "$%DLL_PATH%\\zlib1.dll"
SetOutPath "$INSTDIR\glsl"