Skip to content

Commit 443b435

Browse files
committed
Switch from sdl2 to sdl3
resolves conflicts for opendigitizer which recently switched to sdl3. Signed-off-by: Alexander Krimm <[email protected]>
1 parent 5fb4d05 commit 443b435

File tree

3 files changed

+32
-31
lines changed

3 files changed

+32
-31
lines changed

CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ else()
7373
GIT_TAG v0.16)
7474
FetchContent_MakeAvailable(imgui implot gnuradio4 ut)
7575

76-
find_package(SDL2 REQUIRED)
76+
find_package(SDL3 REQUIRED)
7777
find_package(OpenGL REQUIRED COMPONENTS OpenGL)
7878

7979
# imgui and implot are not CMake Projects, so we have to define their
@@ -83,12 +83,12 @@ else()
8383
${imgui_SOURCE_DIR}/imgui_demo.cpp
8484
${imgui_SOURCE_DIR}/imgui_draw.cpp
8585
${imgui_SOURCE_DIR}/backends/imgui_impl_opengl3.cpp
86-
${imgui_SOURCE_DIR}/backends/imgui_impl_sdl2.cpp
86+
${imgui_SOURCE_DIR}/backends/imgui_impl_sdl3.cpp
8787
${imgui_SOURCE_DIR}/imgui_tables.cpp
8888
${imgui_SOURCE_DIR}/imgui_widgets.cpp
8989
${imgui_SOURCE_DIR}/imgui.cpp
9090
${imgui_SOURCE_DIR}/misc/cpp/imgui_stdlib.cpp)
91-
target_link_libraries(imgui PUBLIC SDL2::SDL2 OpenGL::GL)
91+
target_link_libraries(imgui PUBLIC SDL3::SDL3 OpenGL::GL)
9292
target_compile_options(
9393
imgui PRIVATE -w) # imgui does lots of oldstyle casts and pointer
9494
# arithmethic leading to many warnings

blocklib/timing/src/test-timing.cpp

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
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

689689
std::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

750751
void 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

759760
void 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

775776
void 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
}

docker/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ RUN sudo apt-get update \
3939
&& ( wget -O - https://labs.picotech.com/Release.gpg.key | sudo gpg --dearmor -o /usr/share/keyrings/picotech.gpg ) \
4040
&& (echo 'deb [signed-by=/usr/share/keyrings/picotech.gpg] https://labs.picotech.com/rc/picoscope7/debian/ picoscope main' | sudo tee /etc/apt/sources.list.d/picoscope.list ) \
4141
&& sudo apt update \
42-
&& ( sudo apt install -y udev libusb-1.0-0-dev libps3000a libps4000a libps5000a libps6000 libps6000a libx11-dev libgl1-mesa-dev libsdl2-dev || true ) \
42+
&& ( sudo apt install -y udev libusb-1.0-0-dev libps3000a libps4000a libps5000a libps6000 libps6000a libx11-dev libgl1-mesa-dev libsdl3-dev || true ) \
4343
&& sudo apt-get clean \
4444
&& sudo rm -rf /var/lib/apt/lists/*
4545

0 commit comments

Comments
 (0)