66#include < unordered_set>
77
88// UI
9- #include < SDL.h>
9+ #include < SDL3/ SDL.h>
1010#if defined(IMGUI_IMPL_OPENGL_ES2)
11- #include < SDL_opengles2.h>
11+ #include < SDL3/ SDL_opengles2.h>
1212#else
13- #include < SDL_opengl.h>
13+ #include < SDL3/ SDL_opengl.h>
1414#endif
1515#include " ImScoped.hpp"
1616#include < imgui.h>
1717#include < imgui_impl_opengl3.h>
18- #include < imgui_impl_sdl2 .h>
18+ #include < imgui_impl_sdl3 .h>
1919#include < implot.h>
2020
2121#include < OutputCondition_Proxy.hpp>
@@ -687,39 +687,40 @@ class TimePlot {
687687};
688688
689689std::pair<SDL_Window*, SDL_GLContext> openSDLWindow () {
690- if (SDL_Init (SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0 ) {
690+ if (! SDL_Init (SDL_INIT_VIDEO) ) {
691691 return {nullptr , nullptr };
692692 }
693693 // Decide GL+GLSL versions
694- #if defined(IMGUI_IMPL_OPENGL_ES2)
695- // GL ES 2.0 + GLSL 100
696- const char * glsl_version = " #version 100" ;
697- SDL_GL_SetAttribute (SDL_GL_CONTEXT_FLAGS, 0 );
698- SDL_GL_SetAttribute (SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
699- SDL_GL_SetAttribute (SDL_GL_CONTEXT_MAJOR_VERSION, 2 );
694+
695+ #ifdef __EMSCRIPTEN__
696+ // WebGL2 via GLES 3.0 + GLSL ES 300
697+ SDL_GL_SetAttribute (SDL_GL_CONTEXT_MAJOR_VERSION, 3 );
700698 SDL_GL_SetAttribute (SDL_GL_CONTEXT_MINOR_VERSION, 0 );
701- #elif defined(__APPLE__)
702- // GL 3.2 Core + GLSL 150
703- const char * glsl_version = " #version 150" ;
704- SDL_GL_SetAttribute (SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG); // Always required on Mac
699+ SDL_GL_SetAttribute (SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
700+ // glslVersionOut = "#version 300 es"; //TODO: check compatibility of this
701+ const char * glsl_version = " #version 100" ;
702+ #else
703+ #ifdef __APPLE__
704+ // macOS requires forward-compatible core context ≥ 3.2
705+ SDL_GL_SetAttribute (SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG);
705706 SDL_GL_SetAttribute (SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
706707 SDL_GL_SetAttribute (SDL_GL_CONTEXT_MAJOR_VERSION, 3 );
707708 SDL_GL_SetAttribute (SDL_GL_CONTEXT_MINOR_VERSION, 2 );
709+ const char * glsl_version = " #version 150" ;
708710#else
709- // GL 3.0 + GLSL 130
710- const char * glsl_version = " #version 130" ;
711711 SDL_GL_SetAttribute (SDL_GL_CONTEXT_FLAGS, 0 );
712712 SDL_GL_SetAttribute (SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
713713 SDL_GL_SetAttribute (SDL_GL_CONTEXT_MAJOR_VERSION, 3 );
714- SDL_GL_SetAttribute (SDL_GL_CONTEXT_MINOR_VERSION, 0 );
714+ SDL_GL_SetAttribute (SDL_GL_CONTEXT_MINOR_VERSION, 3 );
715+ const char * glsl_version = " #version 330 core" ;
716+ #endif
715717#endif
716-
717718 // Create window with graphics context
718719 SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1 );
719720 SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 24 );
720721 SDL_GL_SetAttribute (SDL_GL_STENCIL_SIZE, 8 );
721- auto window_flags = static_cast <SDL_WindowFlags>(SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI );
722- SDL_Window* window = SDL_CreateWindow (" Dear ImGui SDL2+OpenGL3 example " , SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED , 1280 , 720 , window_flags);
722+ auto window_flags = static_cast <SDL_WindowFlags>(SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
723+ SDL_Window* window = SDL_CreateWindow (" Fair Timing Util " , 1280 , 720 , window_flags);
723724 if (!window) {
724725 return {nullptr , nullptr };
725726 }
@@ -737,7 +738,7 @@ std::pair<SDL_Window*, SDL_GLContext> openSDLWindow() {
737738 // Setup Platform/Renderer backends
738739
739740 std::print (" Initilalizing SDL2 for OpenGL\n " );
740- ImGui_ImplSDL2_InitForOpenGL (window, gl_context);
741+ ImGui_ImplSDL3_InitForOpenGL (window, gl_context);
741742 std::print (" Initializing OpenGL; glsl_version={}\n " , glsl_version);
742743 if (!ImGui_ImplOpenGL3_Init (glsl_version)) {
743744 return {nullptr , nullptr };
@@ -749,16 +750,16 @@ std::pair<SDL_Window*, SDL_GLContext> openSDLWindow() {
749750
750751void processSDLEvents (SDL_Window* window, bool & done) {
751752 for (SDL_Event event; SDL_PollEvent (&event);) {
752- ImGui_ImplSDL2_ProcessEvent (&event);
753- if (event.type == SDL_QUIT || (event.type == SDL_WINDOWEVENT && event. window . event == SDL_WINDOWEVENT_CLOSE && event.window .windowID == SDL_GetWindowID (window))) {
753+ ImGui_ImplSDL3_ProcessEvent (&event);
754+ if (event.type == SDL_EVENT_QUIT || (event.type == SDL_EVENT_WINDOW_CLOSE_REQUESTED && event.window .windowID == SDL_GetWindowID (window))) {
754755 done = true ;
755756 }
756757 }
757758}
758759
759760void startImGuiFrame () {
760761 ImGui_ImplOpenGL3_NewFrame ();
761- ImGui_ImplSDL2_NewFrame ();
762+ ImGui_ImplSDL3_NewFrame ();
762763 ImGui::NewFrame ();
763764}
764765
@@ -774,10 +775,10 @@ void RenderToSDL(const ImGuiIO& io, SDL_Window* window) {
774775
775776void shutdownSDL (SDL_Window* window, SDL_GLContext gl_context) {
776777 ImGui_ImplOpenGL3_Shutdown ();
777- ImGui_ImplSDL2_Shutdown ();
778+ ImGui_ImplSDL3_Shutdown ();
778779 ImGui::DestroyContext ();
779780
780- SDL_GL_DeleteContext (gl_context);
781+ SDL_GL_DestroyContext (gl_context);
781782 SDL_DestroyWindow (window);
782783 SDL_Quit ();
783784}
0 commit comments