! switched from sdl2 to sdl3, building sdl3 from source

This commit is contained in:
2026-02-26 15:34:52 +01:00
parent 70d23830fc
commit 3935d00cb9
136 changed files with 61 additions and 58813 deletions

View File

@@ -1,11 +1,10 @@
#include "Application.h"
#include "Event.h"
#include "Log.h"
#include "SDL3/SDL_events.h"
#include "imgui.h"
#include "imgui_impl_sdl2.h"
#include "imgui_impl_sdl3.h"
#include "imgui_impl_sdlrenderer2.h"
// #include "imgui_impl_sdlrenderer3.h"
#include "imgui_impl_sdlrenderer3.h"
#if !SDL_VERSION_ATLEAST(2, 0, 17)
#error This backend requires SDL 2.0.17+ because of SDL_RenderGeometry() function
@@ -27,7 +26,7 @@ bool Application::Init() {
LOG_INFO("window width: {0}, height: {1}", GetWindowData().width, GetWindowData().height);
// Init sdl
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER /*| SDL_INIT_GAMECONTROLLER*/) < 0) {
if (SDL_Init(SDL_INIT_VIDEO /*| SDL_INIT_GAMECONTROLLER*/) < 0) {
LOG_ERROR("SDL could not be initialized! {0}", SDL_GetError());
Shutdown();
return false;
@@ -38,8 +37,8 @@ bool Application::Init() {
#endif
// TODO: add the resizable flag and update the window size with the event system
SDL_WindowFlags windowFlags = (SDL_WindowFlags)(SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_RESIZABLE);
m_Window = SDL_CreateWindow(GetWindowData().title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, GetWindowData().width, GetWindowData().height, windowFlags);
SDL_WindowFlags windowFlags = (SDL_WindowFlags)(SDL_WINDOW_RESIZABLE);
m_Window = SDL_CreateWindow(GetWindowData().title, GetWindowData().width, GetWindowData().height, windowFlags);
if (!m_Window) {
LOG_ERROR("SDL window could not be created! {0}", SDL_GetError());
@@ -50,26 +49,13 @@ bool Application::Init() {
LOG_INFO("SDl window created");
}
m_Renderer = SDL_CreateRenderer(m_Window, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED);
m_Renderer = SDL_CreateRenderer(m_Window, nullptr);
if (!m_Renderer) {
LOG_ERROR("Renderer could not be created! {0}", SDL_GetError());
} else {
LOG_INFO("SDL renderer created");
SDL_RendererInfo info;
SDL_GetRendererInfo(m_Renderer, &info);
}
/*m_Surface = SDL_GetWindowSurface(m_Window);
if (!m_Surface) {
LOG_ERROR("SDL surface could not be created! {0}", SDL_GetError());
Shutdown();
return false;
} else {
LOG_INFO("SDl surface created");
}*/
// Imgui init
IMGUI_CHECKVERSION();
ImGui::CreateContext();
@@ -81,8 +67,8 @@ bool Application::Init() {
ImGui::StyleColorsDark();
ImGui_ImplSDL2_InitForSDLRenderer(m_Window, m_Renderer);
ImGui_ImplSDLRenderer2_Init(m_Renderer);
ImGui_ImplSDL3_InitForSDLRenderer(m_Window, m_Renderer);
ImGui_ImplSDLRenderer3_Init(m_Renderer);
return true;
}
@@ -98,26 +84,26 @@ void Application::Run() {
SDL_Event event;
while (SDL_PollEvent(&event)) {
ImGui_ImplSDL2_ProcessEvent(&event);
ImGui_ImplSDL3_ProcessEvent(&event);
if (event.type == SDL_QUIT) {
if (event.type == SDL_EVENT_QUIT) {
SetRunningState(false);
LOG_INFO("Running state: {0}", GetRunningState());
}
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE && event.window.windowID == SDL_GetWindowID(GetSDLWindow())) {
if (event.type == SDL_EVENT_WINDOW_CLOSE_REQUESTED && event.window.windowID == SDL_GetWindowID(GetSDLWindow())) {
SetRunningState(false);
}
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_RESIZED) {
if (event.type == SDL_EVENT_WINDOW_RESIZED) {
SDL_GetWindowSize(GetSDLWindow(), &GetWindowData().width, &GetWindowData().height);
SetSDLWindowSurface(SDL_GetWindowSurface(GetSDLWindow()));
}
}
ImGui_ImplSDLRenderer2_NewFrame();
ImGui_ImplSDL2_NewFrame();
ImGui_ImplSDLRenderer3_NewFrame();
ImGui_ImplSDL3_NewFrame();
ImGui::NewFrame();
if (demoWindowShow) {
@@ -147,10 +133,10 @@ void Application::Run() {
// Rendering
ImGui::Render();
SDL_RenderSetScale(m_Renderer, io.DisplayFramebufferScale.x, io.DisplayFramebufferScale.y);
SDL_SetRenderScale(m_Renderer, io.DisplayFramebufferScale.x, io.DisplayFramebufferScale.y);
SDL_SetRenderDrawColor(m_Renderer, (Uint8)(clearColor.x * 255), (Uint8)(clearColor.y * 255), (Uint8)(clearColor.z * 255), (Uint8)(clearColor.w * 255));
SDL_RenderClear(m_Renderer);
ImGui_ImplSDLRenderer2_RenderDrawData(ImGui::GetDrawData(), m_Renderer);
ImGui_ImplSDLRenderer3_RenderDrawData(ImGui::GetDrawData(), m_Renderer);
SDL_RenderPresent(m_Renderer);
}
}
@@ -158,8 +144,8 @@ void Application::Run() {
void Application::Shutdown() {
LOG_WARN("Shutting down the application!");
ImGui_ImplSDLRenderer2_Shutdown();
ImGui_ImplSDL2_Shutdown();
ImGui_ImplSDLRenderer3_Shutdown();
ImGui_ImplSDL3_Shutdown();
ImGui::DestroyContext();
SDL_DestroyRenderer(m_Renderer);

View File

@@ -1,6 +1,6 @@
#pragma once
#include "SDL.h"
#include "../../libs/sdl3/include/SDL3/SDL.h"
struct WindowData {
int width = 1920;

View File

@@ -1,9 +1,7 @@
#include "SDL.h"
#include "Application.h"
// #include "SDL.h"
#include "Event.h"
#include "../../libs/sdl3/include/SDL3/SDL.h"
#include "Application.h"
#include "Log.h"
void SakuraVNE::ProcessEvents()
{
}
void SakuraVNE::ProcessEvents() {}

View File

@@ -3,14 +3,13 @@
#include "Application.h"
#include "Log.h"
int main(int argc, char* argv[]){
SDL_SetMainReady();
int main(int argc, char *argv[]) {
Application app;
bool success = app.Init();
if(success)
app.Run();
if (success)
app.Run();
return 0;
}
}