added sdl3 backend headers
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
#include "Application.h"
|
||||
#include "Log.h"
|
||||
#include "Event.h"
|
||||
#include "Log.h"
|
||||
#include "imgui.h"
|
||||
#include "imgui_impl_sdl2.h"
|
||||
#include "imgui_impl_sdl3.h"
|
||||
#include "imgui_impl_sdlrenderer2.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
|
||||
@@ -12,16 +14,11 @@
|
||||
WindowData Application::m_WindowData;
|
||||
bool Application::m_isRunning = false;
|
||||
|
||||
Application::Application()
|
||||
: m_Renderer(nullptr){}
|
||||
Application::Application() : m_Renderer(nullptr) {}
|
||||
|
||||
Application::~Application()
|
||||
{
|
||||
Shutdown();
|
||||
}
|
||||
Application::~Application() { Shutdown(); }
|
||||
|
||||
bool Application::Init()
|
||||
{
|
||||
bool Application::Init() {
|
||||
SetRunningState(true);
|
||||
|
||||
SakuraVNE::Log::Init();
|
||||
@@ -30,8 +27,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_TIMER /*| SDL_INIT_GAMECONTROLLER*/) < 0) {
|
||||
LOG_ERROR("SDL could not be initialized! {0}", SDL_GetError());
|
||||
Shutdown();
|
||||
return false;
|
||||
@@ -41,20 +37,16 @@ bool Application::Init()
|
||||
SDL_SetHint(SDL_HINT_IME_SHOW_UI, "1");
|
||||
#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);
|
||||
|
||||
if (!m_Window)
|
||||
{
|
||||
if (!m_Window) {
|
||||
LOG_ERROR("SDL window could not be created! {0}", SDL_GetError());
|
||||
Shutdown();
|
||||
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
LOG_INFO("SDl window created");
|
||||
}
|
||||
|
||||
@@ -68,25 +60,22 @@ bool Application::Init()
|
||||
SDL_GetRendererInfo(m_Renderer, &info);
|
||||
}
|
||||
|
||||
m_Surface = SDL_GetWindowSurface(m_Window);
|
||||
if (!m_Surface)
|
||||
{
|
||||
/*m_Surface = SDL_GetWindowSurface(m_Window);
|
||||
if (!m_Surface) {
|
||||
LOG_ERROR("SDL surface could not be created! {0}", SDL_GetError());
|
||||
Shutdown();
|
||||
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
LOG_INFO("SDl surface created");
|
||||
}
|
||||
|
||||
}*/
|
||||
|
||||
// Imgui init
|
||||
IMGUI_CHECKVERSION();
|
||||
ImGui::CreateContext();
|
||||
|
||||
ImGuiIO& io = ImGui::GetIO(); (void) io;
|
||||
ImGuiIO &io = ImGui::GetIO();
|
||||
(void)io;
|
||||
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
|
||||
// io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad;
|
||||
|
||||
@@ -95,34 +84,28 @@ bool Application::Init()
|
||||
ImGui_ImplSDL2_InitForSDLRenderer(m_Window, m_Renderer);
|
||||
ImGui_ImplSDLRenderer2_Init(m_Renderer);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Application::Run()
|
||||
{
|
||||
void Application::Run() {
|
||||
bool demoWindowShow = true;
|
||||
bool showOtherWindow = false;
|
||||
ImVec4 clearColor = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
|
||||
|
||||
ImGuiIO &io = ImGui::GetIO();
|
||||
|
||||
while (GetRunningState())
|
||||
{
|
||||
while (GetRunningState()) {
|
||||
SDL_Event event;
|
||||
|
||||
while (SDL_PollEvent(&event))
|
||||
{
|
||||
while (SDL_PollEvent(&event)) {
|
||||
ImGui_ImplSDL2_ProcessEvent(&event);
|
||||
|
||||
if (event.type == SDL_QUIT)
|
||||
{
|
||||
if (event.type == SDL_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_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE && event.window.windowID == SDL_GetWindowID(GetSDLWindow())) {
|
||||
SetRunningState(false);
|
||||
}
|
||||
|
||||
@@ -153,7 +136,8 @@ void Application::Run()
|
||||
ImGui::SliderFloat("float", &f, 0.0f, 1.0f);
|
||||
ImGui::ColorEdit3("clear color edit", (float *)&clearColor);
|
||||
|
||||
if(ImGui::Button("Button")) counter++;
|
||||
if (ImGui::Button("Button"))
|
||||
counter++;
|
||||
|
||||
ImGui::SameLine();
|
||||
ImGui::Text("counter = %d", counter);
|
||||
@@ -171,8 +155,7 @@ void Application::Run()
|
||||
}
|
||||
}
|
||||
|
||||
void Application::Shutdown()
|
||||
{
|
||||
void Application::Shutdown() {
|
||||
LOG_WARN("Shutting down the application!");
|
||||
|
||||
ImGui_ImplSDLRenderer2_Shutdown();
|
||||
|
||||
Reference in New Issue
Block a user