diff --git a/Source/Tools/FEXConfig/CMakeLists.txt b/Source/Tools/FEXConfig/CMakeLists.txt index 965579e9e..030a83a96 100644 --- a/Source/Tools/FEXConfig/CMakeLists.txt +++ b/Source/Tools/FEXConfig/CMakeLists.txt @@ -1,24 +1,24 @@ set(NAME FEXConfig) set(SRCS Main.cpp - ../Debugger/Context.cpp - ${CMAKE_SOURCE_DIR}/External/imgui/examples/imgui_impl_glfw.cpp + ${CMAKE_SOURCE_DIR}/External/imgui/examples/imgui_impl_sdl.cpp ${CMAKE_SOURCE_DIR}/External/imgui/examples/imgui_impl_opengl3.cpp ) find_library(EPOXY_LIBRARY epoxy) -find_library(GLFW_LIBRARY glfw3) +find_package(SDL2 REQUIRED) add_definitions(-DIMGUI_IMPL_OPENGL_LOADER_CUSTOM=) add_executable(${NAME} ${SRCS}) target_include_directories(${NAME} PRIVATE ${LLVM_INCLUDE_DIRS}) +target_include_directories(${NAME} PRIVATE ${SDL2_INCLUDE_DIRS}) target_include_directories(${NAME} PRIVATE ${CMAKE_SOURCE_DIR}/Source/) target_include_directories(${NAME} PRIVATE ${CMAKE_SOURCE_DIR}/Source/Tools/Debugger/) target_include_directories(${NAME} PRIVATE ${CMAKE_SOURCE_DIR}/External/imgui/examples/) -target_link_libraries(${NAME} PRIVATE FEXCore Common CommonCore pthread epoxy glfw X11 EGL imgui tiny-json json-maker) +target_link_libraries(${NAME} PRIVATE FEXCore Common CommonCore pthread epoxy ${SDL2_LIBRARIES} X11 EGL imgui tiny-json json-maker) install(TARGETS ${NAME} RUNTIME diff --git a/Source/Tools/FEXConfig/Main.cpp b/Source/Tools/FEXConfig/Main.cpp index 7429dcd37..50eb7669e 100644 --- a/Source/Tools/FEXConfig/Main.cpp +++ b/Source/Tools/FEXConfig/Main.cpp @@ -1,19 +1,19 @@ #include "Common/Config.h" -#include "Context.h" #include #define YES_IMGUIFILESYSTEM #include #include +#include +#include #include -#include #include #include -#include "imgui_impl_glfw.h" +#include "imgui_impl_sdl.h" #include "imgui_impl_opengl3.h" namespace { - static double GlobalTime{}; + static std::chrono::time_point GlobalTime{}; static bool ConfigOpen{}; static bool ConfigChanged{}; @@ -358,10 +358,11 @@ namespace { ImGui::EndTabBar(); } - void DrawUI(GLContext::Context *Context) { + void DrawUI() { ImGuiIO& io = ImGui::GetIO(); - double current_time = glfwGetTime(); - io.DeltaTime = GlobalTime > 0.0 ? static_cast(current_time - GlobalTime) : static_cast(1.0f/60.0f); + auto current_time = std::chrono::high_resolution_clock::now(); + auto Diff = std::chrono::duration_cast(current_time - GlobalTime); + io.DeltaTime = Diff.count() > 0 ? Diff.count() : 1.0f/60.0f; GlobalTime = current_time; ImGui::NewFrame(); @@ -440,7 +441,7 @@ namespace { FillConfigWindow(); } - if (ImGui::IsKeyPressed(GLFW_KEY_E) && io.KeyCtrl) { + if (ImGui::IsKeyPressed(SDL_SCANCODE_E) && io.KeyCtrl) { ImGui::OpenPopup(SavedPopupAppName); } @@ -453,7 +454,7 @@ namespace { ImGui::CloseCurrentPopup(); } - if (ImGui::IsKeyPressed(GLFW_KEY_ESCAPE)) { + if (ImGui::IsKeyPressed(SDL_SCANCODE_ESCAPE)) { ImGui::CloseCurrentPopup(); } ImGui::EndPopup(); @@ -480,33 +481,33 @@ namespace { } if (Selected.Open || - (ImGui::IsKeyPressed(GLFW_KEY_O) && io.KeyCtrl && !io.KeyShift)) { + (ImGui::IsKeyPressed(SDL_SCANCODE_O) && io.KeyCtrl && !io.KeyShift)) { SelectedOpenFile = true; } if (Selected.OpenDefault || - (ImGui::IsKeyPressed(GLFW_KEY_O) && io.KeyCtrl && io.KeyShift)) { + (ImGui::IsKeyPressed(SDL_SCANCODE_O) && io.KeyCtrl && io.KeyShift)) { OpenFile(FEX::Config::GetConfigFileLocation()); } if (Selected.LoadDefault || - (ImGui::IsKeyPressed(GLFW_KEY_D) && io.KeyCtrl && io.KeyShift)) { + (ImGui::IsKeyPressed(SDL_SCANCODE_D) && io.KeyCtrl && io.KeyShift)) { LoadDefaultSettings(); } if (Selected.Save || - (ImGui::IsKeyPressed(GLFW_KEY_S) && io.KeyCtrl && !io.KeyShift)) { + (ImGui::IsKeyPressed(SDL_SCANCODE_S) && io.KeyCtrl && !io.KeyShift)) { SaveFile(ConfigFilename); } if (Selected.SaveAs || - (ImGui::IsKeyPressed(GLFW_KEY_S) && io.KeyCtrl && io.KeyShift)) { + (ImGui::IsKeyPressed(SDL_SCANCODE_S) && io.KeyCtrl && io.KeyShift)) { SelectedSaveFileAs = true; } if (Selected.SaveDefault || - (ImGui::IsKeyPressed(GLFW_KEY_P) && io.KeyCtrl && io.KeyShift)) { + (ImGui::IsKeyPressed(SDL_SCANCODE_P) && io.KeyCtrl && io.KeyShift)) { SaveFile(FEX::Config::GetConfigFileLocation()); } if (Selected.Close || - (ImGui::IsKeyPressed(GLFW_KEY_W) && io.KeyCtrl && !io.KeyShift)) { + (ImGui::IsKeyPressed(SDL_SCANCODE_W) && io.KeyCtrl && !io.KeyShift)) { CloseConfig(); } @@ -537,8 +538,27 @@ namespace { int main() { std::string ImGUIConfig = FEX::Config::GetConfigFolder(false) + "FEXConfig_imgui.ini"; - auto Context = GLContext::CreateContext(); - Context->Create("#FEXConfig"); + // Setup SDL + if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0) + { + printf("Error: %s\n", SDL_GetError()); + return -1; + } + + SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, 0); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0); + + // Create window with graphics context + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); + SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); + SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); + SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI); + SDL_Window* window = SDL_CreateWindow("#FEXConfig", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 640, window_flags); + SDL_GLContext gl_context = SDL_GL_CreateContext(window); + SDL_GL_MakeCurrent(window, gl_context); + SDL_GL_SetSwapInterval(1); // Enable vsync // Setup Dear ImGui context IMGUI_CHECKVERSION(); @@ -549,39 +569,54 @@ int main() { io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows io.IniFilename = &ImGUIConfig.at(0); - GLFWwindow *Window = static_cast(Context->GetWindow()); - // Setup Platform/Renderer bindings - ImGui_ImplGlfw_InitForOpenGL(Window, true); + ImGui_ImplSDL2_InitForOpenGL(window, gl_context); const char* glsl_version = "#version 130"; ImGui_ImplOpenGL3_Init(glsl_version); - while (!glfwWindowShouldClose(Window)) { - glfwWaitEvents(); + GlobalTime = std::chrono::high_resolution_clock::now(); + + bool Done{}; + while (!Done) { + SDL_Event event; + if (SDL_WaitEvent(nullptr)) + { + while (SDL_PollEvent(&event)) { + ImGui_ImplSDL2_ProcessEvent(&event); + if (event.type == SDL_QUIT) + Done = true; + if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE && event.window.windowID == SDL_GetWindowID(window)) + Done = true; + } + } // Start the Dear ImGui frame ImGui_ImplOpenGL3_NewFrame(); - ImGui_ImplGlfw_NewFrame(); - DrawUI(Context.get()); + ImGui_ImplSDL2_NewFrame(window); + DrawUI(); glClear(GL_COLOR_BUFFER_BIT); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) { - GLFWwindow* backup_current_context = glfwGetCurrentContext(); + SDL_Window* backup_current_window = SDL_GL_GetCurrentWindow(); + SDL_GLContext backup_current_context = SDL_GL_GetCurrentContext(); ImGui::UpdatePlatformWindows(); ImGui::RenderPlatformWindowsDefault(); - glfwMakeContextCurrent(backup_current_context); + SDL_GL_MakeCurrent(backup_current_window, backup_current_context); } - Context->Swap(); + SDL_GL_SwapWindow(window); } // Cleanup ImGui_ImplOpenGL3_Shutdown(); - ImGui_ImplGlfw_Shutdown(); + ImGui_ImplSDL2_Shutdown(); ImGui::DestroyContext(); - Context->Shutdown(); + + SDL_GL_DeleteContext(gl_context); + SDL_DestroyWindow(window); + SDL_Quit(); return 0; }