From 77f726c6ca35e2c84bdfcd2937615f4b1f604274 Mon Sep 17 00:00:00 2001 From: jammy3855 Date: Tue, 17 Feb 2026 22:13:46 -0600 Subject: [PATCH 1/3] Started SDL3 Renderer example --- .../example_sdl3_renderer/CMakeLists.txt | 98 ++++++++++++ backend_test/example_sdl3_renderer/README.md | 2 + backend_test/example_sdl3_renderer/main.c | 151 ++++++++++++++++++ 3 files changed, 251 insertions(+) create mode 100644 backend_test/example_sdl3_renderer/CMakeLists.txt create mode 100644 backend_test/example_sdl3_renderer/README.md create mode 100644 backend_test/example_sdl3_renderer/main.c diff --git a/backend_test/example_sdl3_renderer/CMakeLists.txt b/backend_test/example_sdl3_renderer/CMakeLists.txt new file mode 100644 index 0000000..7922a57 --- /dev/null +++ b/backend_test/example_sdl3_renderer/CMakeLists.txt @@ -0,0 +1,98 @@ +cmake_minimum_required(VERSION 3.5) +Project(cimgui_sdl3_renderer) +if(WIN32) # to make mingw work as all the others +set(CMAKE_SHARED_LIBRARY_PREFIX "") +endif(WIN32) +# general settings + + +if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../../imgui/backends) + set(BACKENDS_FOLDER "../../imgui/backends/") +else() + set(BACKENDS_FOLDER "../../imgui/examples/") +endif() + +if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../../imgui/imgui_tables.cpp) + set(TABLES_SOURCE "../../imgui/imgui_tables.cpp") +else() + set(TABLES_SOURCE "") +endif() + +include_directories(../../imgui ../../imgui/backends) + + +include_directories(../../) +set(IMGUI_SOURCES ../../cimgui.cpp +../../cimgui_impl.cpp +../../imgui/imgui.cpp +../../imgui/imgui_draw.cpp +../../imgui/imgui_demo.cpp +../../imgui/imgui_widgets.cpp +${TABLES_SOURCE} +) + +set(IMGUI_SOURCES_sdl) +set(IMGUI_LIBRARIES ) + + +#optional adding freetype +option(IMGUI_FREETYPE "add Freetype2" OFF) + +if(IMGUI_FREETYPE) + FIND_PACKAGE(freetype REQUIRED PATHS ${FREETYPE_PATH}) + list(APPEND IMGUI_LIBRARIES freetype) + list(APPEND IMGUI_SOURCES ../../imgui/misc/freetype/imgui_freetype.cpp) + add_definitions("-DCIMGUI_FREETYPE=1") +endif(IMGUI_FREETYPE) + +#sdl3 +list(APPEND IMGUI_SOURCES ${BACKENDS_FOLDER}imgui_impl_sdl3.cpp) +include(FetchContent) +Set(FETCHCONTENT_QUIET FALSE) + +FetchContent_Declare( + SDL3 + GIT_REPOSITORY https://github.com/libsdl-org/SDL.git + GIT_TAG release-3.2.8 + #GIT_SHALLOW TRUE + GIT_PROGRESS TRUE +) +FetchContent_GetProperties(SDL3) +if (NOT sdl3_POPULATED) + set(FETCHCONTENT_QUIET NO) + FetchContent_Populate(SDL3) + set(SDL_TEST OFF CACHE BOOL "" FORCE) + set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE) + add_subdirectory(${sdl3_SOURCE_DIR} ${sdl3_BINARY_DIR}) +endif() +include_directories(${SDL3_SOURCE_DIR}/include) + + +#if dynamic SDL3 then install +# install(TARGETS SDL3 RUNTIME DESTINATION ${CMAKE_CURRENT_BINARY_DIR} + # LIBRARY DESTINATION ${CMAKE_CURRENT_BINARY_DIR} +# ) + +add_library(cimgui_sdl STATIC ${IMGUI_SOURCES}) +target_compile_definitions(cimgui_sdl PUBLIC "-DIMGUI_USER_CONFIG=\"../cimconfig.h\"") +target_compile_definitions(cimgui_sdl PUBLIC "-DIMGUI_DISABLE_OBSOLETE_FUNCTIONS=1") +target_compile_definitions(cimgui_sdl PUBLIC -DCIMGUI_USE_SDL3) +if (WIN32) + target_compile_definitions(cimgui_sdl PUBLIC "-DIMGUI_IMPL_API=extern \"C\" __declspec\(dllexport\)") +else(WIN32) + target_compile_definitions(cimgui_sdl PUBLIC "-DIMGUI_IMPL_API=extern \"C\" ") +endif(WIN32) +#target_link_libraries(cimgui_sdl ${IMGUI_LIBRARIES} SDL3-static) + +#using library +add_executable(test_sdl main.c) +target_compile_definitions(test_sdl + PUBLIC + CIMGUI_DEFINE_ENUMS_AND_STRUCTS=1 + CIMGUI_USE_SDL3=1 +) +if (MINGW) +target_link_options(test_sdl PRIVATE "-mconsole") +endif() +target_link_libraries(test_sdl SDL3-static cimgui_sdl ${IMGUI_LIBRARIES}) + diff --git a/backend_test/example_sdl3_renderer/README.md b/backend_test/example_sdl3_renderer/README.md new file mode 100644 index 0000000..7ac04b8 --- /dev/null +++ b/backend_test/example_sdl3_renderer/README.md @@ -0,0 +1,2 @@ + +To build use `cmake path_to_example_sdl3_vulkan` and then `make install` diff --git a/backend_test/example_sdl3_renderer/main.c b/backend_test/example_sdl3_renderer/main.c new file mode 100644 index 0000000..6fcf882 --- /dev/null +++ b/backend_test/example_sdl3_renderer/main.c @@ -0,0 +1,151 @@ +#include +#include +#include +#include + +#include + +#include +#include + + +#define igGetIO igGetIO_Nil + +int main() { + if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMEPAD)) { + fprintf(stderr, "Failed to init video! %s", SDL_GetError()); + return 1; + }; + + float main_scale = SDL_GetDisplayContentScale(SDL_GetPrimaryDisplay()); + SDL_WindowFlags window_flags = SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIDDEN | SDL_WINDOW_HIGH_PIXEL_DENSITY; + SDL_Window* window = NULL; + SDL_Renderer* renderer = NULL; + if (!SDL_CreateWindowAndRenderer("Dear ImGui SDL3 Renderer example", (int)(1280 * main_scale), (int)(720 * main_scale), window_flags, &window, &renderer)) + { + printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError()); + return -1; + } + SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED); + SDL_ShowWindow(window); + + // Setup Dear ImGui context + //IMGUI_CHECKVERSION(); + igCreateContext(NULL); + ImGuiIO* io = igGetIO(); (void)io; + io->ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls + io->ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls + + // Setup Dear ImGui style + igStyleColorsDark(NULL); + //igStyleColorsLight(NULL); + // Setup scaling + ImGuiStyle* style = igGetStyle(); + ImGuiStyle_ScaleAllSizes(style, main_scale); // Bake a fixed style scale. (until we have a solution for dynamic style scaling, changing this requires resetting Style + calling this again) + style->FontScaleDpi = main_scale; // Set initial font scale. (using io.ConfigDpiScaleFonts=true makes this unnecessary. We leave both here for documentation purpose) + io->ConfigDpiScaleFonts = true; // [Experimental] Automatically overwrite style.FontScaleDpi in Begin() when Monitor DPI changes. This will scale fonts but _NOT_ scale sizes/padding for now. + io->ConfigDpiScaleViewports = true; // [Experimental] Scale Dear ImGui and Platform Windows when Monitor DPI changes. + + // Setup Platform/Renderer backends + ImGui_ImplSDL3_InitForSDLRenderer(window, renderer); + // finish loading data + + // Our state + bool show_demo_window = true; + bool show_another_window = false; + ImVec4 clear_color; + clear_color.x = 0.45f; + clear_color.y = 0.55f; + clear_color.z = 0.60f; + clear_color.w = 1.00f; + + // Main loop + bool done = false; + while (!done) + { + // Poll and handle events (inputs, window resize, etc.) + // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs. + // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application, or clear/overwrite your copy of the mouse data. + // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application, or clear/overwrite your copy of the keyboard data. + // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags. + // [If using SDL_MAIN_USE_CALLBACKS: call ImGui_ImplSDL3_ProcessEvent() from your SDL_AppEvent() function] + SDL_Event event; + while (SDL_PollEvent(&event)) + { + ImGui_ImplSDL3_ProcessEvent(&event); + if (event.type == SDL_EVENT_QUIT) + done = true; + if (event.type == SDL_EVENT_WINDOW_CLOSE_REQUESTED && event.window.windowID == SDL_GetWindowID(window)) + done = true; + } + + // [If using SDL_MAIN_USE_CALLBACKS: all code below would likely be your SDL_AppIterate() function] + if (SDL_GetWindowFlags(window) & SDL_WINDOW_MINIMIZED) + { + SDL_Delay(10); + continue; + } + + // Start the Dear ImGui frame + ImGui_ImplSDL3_NewFrame(); + igNewFrame(); + + // 1. Show the big demo window (Most of the sample code is in igShowDemoWindow()! You can browse its code to learn more about Dear ImGui!). + if (show_demo_window) + igShowDemoWindow(&show_demo_window); + + // 2. Show a simple window that we create ourselves. We use a Begin/End pair to create a named window. + { + static float f = 0.0f; + static int counter = 0; + + igBegin("Hello, world!", NULL, 0); // Create a window called "Hello, world!" and append into it. + + igText("This is some useful text."); // Display some text (you can use a format strings too) + igCheckbox("Demo Window", &show_demo_window); // Edit bools storing our window open/close state + igCheckbox("Another Window", &show_another_window); + + igSliderFloat("float", &f, 0.0f, 1.0f, "%.3f", 0); // Edit 1 float using a slider from 0.0f to 1.0f + igColorEdit4("clear color", (float*)&clear_color, 0); // Edit 3 floats representing a color + + ImVec2 buttonSize; + buttonSize.x = 0; + buttonSize.y = 0; + if (igButton("Button", buttonSize)) // Buttons return true when clicked (most widgets return true when edited/activated) + counter++; + igSameLine(0.0f, -1.0f); + igText("counter = %d", counter); + + igText("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io->Framerate, io->Framerate); + igEnd(); + } + + // 3. Show another simple window. + if (show_another_window) + { + igBegin("Another Window", &show_another_window, 0); // Pass a pointer to our bool variable (the window will have a closing button that will clear the bool when clicked) + igText("Hello from another window!"); + ImVec2 buttonSize; + buttonSize.x = 0; buttonSize.y = 0; + if (igButton("Close Me", buttonSize)) + show_another_window = false; + igEnd(); + } + + // Rendering + igRender(); + ImDrawData* draw_data = igGetDrawData(); + const bool is_minimized = (draw_data->DisplaySize.x <= 0.0f || draw_data->DisplaySize.y <= 0.0f); + } + + // Cleanup + // [If using SDL_MAIN_USE_CALLBACKS: all code below would likely be your SDL_AppQuit() function] + ImGui_ImplSDL3_Shutdown(); + igDestroyContext(NULL); + + SDL_DestroyRenderer(renderer); + SDL_DestroyWindow(window); + SDL_Quit(); + + return 0; +} From ee8fbaaff4aad8f0b5bc9d1cc2b12548e075edb5 Mon Sep 17 00:00:00 2001 From: jammy3855 Date: Thu, 19 Feb 2026 21:44:03 -0600 Subject: [PATCH 2/3] SDLRenderer3 example working --- .../example_sdl3_renderer/CMakeLists.txt | 107 ++++-------------- backend_test/example_sdl3_renderer/README.md | 16 ++- backend_test/example_sdl3_renderer/main.c | 7 ++ 3 files changed, 43 insertions(+), 87 deletions(-) diff --git a/backend_test/example_sdl3_renderer/CMakeLists.txt b/backend_test/example_sdl3_renderer/CMakeLists.txt index 7922a57..8d36cc5 100644 --- a/backend_test/example_sdl3_renderer/CMakeLists.txt +++ b/backend_test/example_sdl3_renderer/CMakeLists.txt @@ -1,98 +1,33 @@ -cmake_minimum_required(VERSION 3.5) -Project(cimgui_sdl3_renderer) -if(WIN32) # to make mingw work as all the others -set(CMAKE_SHARED_LIBRARY_PREFIX "") -endif(WIN32) -# general settings +cmake_minimum_required(VERSION 3.30) +project(cimgui_sdlrenderer3 LANGUAGES C CXX) +set(CMAKE_C_STANDARD 11) -if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../../imgui/backends) - set(BACKENDS_FOLDER "../../imgui/backends/") -else() - set(BACKENDS_FOLDER "../../imgui/examples/") -endif() - -if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../../imgui/imgui_tables.cpp) - set(TABLES_SOURCE "../../imgui/imgui_tables.cpp") -else() - set(TABLES_SOURCE "") -endif() - -include_directories(../../imgui ../../imgui/backends) - - -include_directories(../../) -set(IMGUI_SOURCES ../../cimgui.cpp -../../cimgui_impl.cpp -../../imgui/imgui.cpp -../../imgui/imgui_draw.cpp -../../imgui/imgui_demo.cpp -../../imgui/imgui_widgets.cpp -${TABLES_SOURCE} -) - -set(IMGUI_SOURCES_sdl) -set(IMGUI_LIBRARIES ) - - -#optional adding freetype -option(IMGUI_FREETYPE "add Freetype2" OFF) - -if(IMGUI_FREETYPE) - FIND_PACKAGE(freetype REQUIRED PATHS ${FREETYPE_PATH}) - list(APPEND IMGUI_LIBRARIES freetype) - list(APPEND IMGUI_SOURCES ../../imgui/misc/freetype/imgui_freetype.cpp) - add_definitions("-DCIMGUI_FREETYPE=1") -endif(IMGUI_FREETYPE) - -#sdl3 -list(APPEND IMGUI_SOURCES ${BACKENDS_FOLDER}imgui_impl_sdl3.cpp) include(FetchContent) -Set(FETCHCONTENT_QUIET FALSE) FetchContent_Declare( - SDL3 - GIT_REPOSITORY https://github.com/libsdl-org/SDL.git - GIT_TAG release-3.2.8 - #GIT_SHALLOW TRUE - GIT_PROGRESS TRUE + sdl3 + URL https://github.com/libsdl-org/SDL/releases/download/release-3.2.8/SDL3-3.2.8.tar.gz ) -FetchContent_GetProperties(SDL3) -if (NOT sdl3_POPULATED) - set(FETCHCONTENT_QUIET NO) - FetchContent_Populate(SDL3) - set(SDL_TEST OFF CACHE BOOL "" FORCE) - set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE) - add_subdirectory(${sdl3_SOURCE_DIR} ${sdl3_BINARY_DIR}) -endif() -include_directories(${SDL3_SOURCE_DIR}/include) +set(SDL_TEST_LIBRARY OFF CACHE BOOL "" FORCE) +FetchContent_MakeAvailable(sdl3) -#if dynamic SDL3 then install -# install(TARGETS SDL3 RUNTIME DESTINATION ${CMAKE_CURRENT_BINARY_DIR} - # LIBRARY DESTINATION ${CMAKE_CURRENT_BINARY_DIR} -# ) +include(../cmake/GenerateCimguiBindings.cmake) -add_library(cimgui_sdl STATIC ${IMGUI_SOURCES}) -target_compile_definitions(cimgui_sdl PUBLIC "-DIMGUI_USER_CONFIG=\"../cimconfig.h\"") -target_compile_definitions(cimgui_sdl PUBLIC "-DIMGUI_DISABLE_OBSOLETE_FUNCTIONS=1") -target_compile_definitions(cimgui_sdl PUBLIC -DCIMGUI_USE_SDL3) -if (WIN32) - target_compile_definitions(cimgui_sdl PUBLIC "-DIMGUI_IMPL_API=extern \"C\" __declspec\(dllexport\)") -else(WIN32) - target_compile_definitions(cimgui_sdl PUBLIC "-DIMGUI_IMPL_API=extern \"C\" ") -endif(WIN32) -#target_link_libraries(cimgui_sdl ${IMGUI_LIBRARIES} SDL3-static) +set(inclulist ${sdl3_SOURCE_DIR}/include) +GenerateCimguiBindings(cimgui_with_backend sdl3 sdlrenderer3 inclulist) +target_link_libraries(cimgui_with_backend PRIVATE SDL3::SDL3) -#using library -add_executable(test_sdl main.c) -target_compile_definitions(test_sdl - PUBLIC +add_executable(${PROJECT_NAME} + main.c +) + +target_link_libraries(${PROJECT_NAME} PRIVATE SDL3::SDL3 cimgui_with_backend) +target_compile_definitions( + ${PROJECT_NAME} + PRIVATE CIMGUI_DEFINE_ENUMS_AND_STRUCTS=1 - CIMGUI_USE_SDL3=1 + CIMGUI_USE_SDL3=1 + CIMGUI_USE_SDLRENDERER3=1 ) -if (MINGW) -target_link_options(test_sdl PRIVATE "-mconsole") -endif() -target_link_libraries(test_sdl SDL3-static cimgui_sdl ${IMGUI_LIBRARIES}) - diff --git a/backend_test/example_sdl3_renderer/README.md b/backend_test/example_sdl3_renderer/README.md index 7ac04b8..1d91a4b 100644 --- a/backend_test/example_sdl3_renderer/README.md +++ b/backend_test/example_sdl3_renderer/README.md @@ -1,2 +1,16 @@ +# SDLGPU3 + +This example is a little different from the others, because `cimgui` doesn't come with bindings for the SDLGPU3 backend out of the box. Instead, this example shows how to generate the necessary bindings during cmake's configure time, then add the compiled library as a target for your application to link to. + +For the generation phase from cmake you need LuaJIT to be present. + +## Building + +From the build directory of your choice: + +`cmake path_to_example_sdlgpu3` + +and after + +`make` -To build use `cmake path_to_example_sdl3_vulkan` and then `make install` diff --git a/backend_test/example_sdl3_renderer/main.c b/backend_test/example_sdl3_renderer/main.c index 6fcf882..2549478 100644 --- a/backend_test/example_sdl3_renderer/main.c +++ b/backend_test/example_sdl3_renderer/main.c @@ -48,6 +48,7 @@ int main() { // Setup Platform/Renderer backends ImGui_ImplSDL3_InitForSDLRenderer(window, renderer); + ImGui_ImplSDLRenderer3_Init(renderer); // finish loading data // Our state @@ -87,6 +88,9 @@ int main() { } // Start the Dear ImGui frame + SDL_SetRenderDrawColorFloat(renderer, clear_color.x, clear_color.y, clear_color.z, clear_color.w); + SDL_RenderClear(renderer); + ImGui_ImplSDLRenderer3_NewFrame(); ImGui_ImplSDL3_NewFrame(); igNewFrame(); @@ -136,11 +140,14 @@ int main() { igRender(); ImDrawData* draw_data = igGetDrawData(); const bool is_minimized = (draw_data->DisplaySize.x <= 0.0f || draw_data->DisplaySize.y <= 0.0f); + ImGui_ImplSDLRenderer3_RenderDrawData(draw_data, renderer); + SDL_RenderPresent(renderer); } // Cleanup // [If using SDL_MAIN_USE_CALLBACKS: all code below would likely be your SDL_AppQuit() function] ImGui_ImplSDL3_Shutdown(); + ImGui_ImplSDLRenderer3_Shutdown(); igDestroyContext(NULL); SDL_DestroyRenderer(renderer); From 2cb5b7d19ba12aa22f33ba93872c74c1b4611e78 Mon Sep 17 00:00:00 2001 From: jammy3855 Date: Thu, 19 Feb 2026 23:24:48 -0600 Subject: [PATCH 3/3] Minor adjustments --- backend_test/example_sdl3_renderer/README.md | 16 ----------- .../CMakeLists.txt | 7 +++-- backend_test/example_sdl_renderer3/README.md | 16 +++++++++++ .../main.c | 28 +++++++++---------- 4 files changed, 35 insertions(+), 32 deletions(-) delete mode 100644 backend_test/example_sdl3_renderer/README.md rename backend_test/{example_sdl3_renderer => example_sdl_renderer3}/CMakeLists.txt (82%) create mode 100644 backend_test/example_sdl_renderer3/README.md rename backend_test/{example_sdl3_renderer => example_sdl_renderer3}/main.c (86%) diff --git a/backend_test/example_sdl3_renderer/README.md b/backend_test/example_sdl3_renderer/README.md deleted file mode 100644 index 1d91a4b..0000000 --- a/backend_test/example_sdl3_renderer/README.md +++ /dev/null @@ -1,16 +0,0 @@ -# SDLGPU3 - -This example is a little different from the others, because `cimgui` doesn't come with bindings for the SDLGPU3 backend out of the box. Instead, this example shows how to generate the necessary bindings during cmake's configure time, then add the compiled library as a target for your application to link to. - -For the generation phase from cmake you need LuaJIT to be present. - -## Building - -From the build directory of your choice: - -`cmake path_to_example_sdlgpu3` - -and after - -`make` - diff --git a/backend_test/example_sdl3_renderer/CMakeLists.txt b/backend_test/example_sdl_renderer3/CMakeLists.txt similarity index 82% rename from backend_test/example_sdl3_renderer/CMakeLists.txt rename to backend_test/example_sdl_renderer3/CMakeLists.txt index 8d36cc5..f1e83e1 100644 --- a/backend_test/example_sdl3_renderer/CMakeLists.txt +++ b/backend_test/example_sdl_renderer3/CMakeLists.txt @@ -6,8 +6,11 @@ set(CMAKE_C_STANDARD 11) include(FetchContent) FetchContent_Declare( - sdl3 - URL https://github.com/libsdl-org/SDL/releases/download/release-3.2.8/SDL3-3.2.8.tar.gz + sdl3 + GIT_REPOSITORY https://github.com/libsdl-org/SDL.git + GIT_TAG release-3.4.0 + #GIT_SHALLOW TRUE + GIT_PROGRESS TRUE ) set(SDL_TEST_LIBRARY OFF CACHE BOOL "" FORCE) diff --git a/backend_test/example_sdl_renderer3/README.md b/backend_test/example_sdl_renderer3/README.md new file mode 100644 index 0000000..17e1567 --- /dev/null +++ b/backend_test/example_sdl_renderer3/README.md @@ -0,0 +1,16 @@ +# SDLRenderer3 + +This example takes from `example_sdlgpu3`. We need to generate bindings for SDLRenderer3 backend because they are not native to `cimgui`. Then you can add the compiled library for linking in your application. + +For the generation phase from cmake you need LuaJIT to be present. + +## Building + +From the build directory of your choice: + +`cmake path_to_example_sdlgpu3` + +Then simply run: + +`make` + diff --git a/backend_test/example_sdl3_renderer/main.c b/backend_test/example_sdl_renderer3/main.c similarity index 86% rename from backend_test/example_sdl3_renderer/main.c rename to backend_test/example_sdl_renderer3/main.c index 2549478..4d7fcf1 100644 --- a/backend_test/example_sdl3_renderer/main.c +++ b/backend_test/example_sdl_renderer3/main.c @@ -8,15 +8,16 @@ #include #include - #define igGetIO igGetIO_Nil int main() { + // Setup SDL library if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMEPAD)) { fprintf(stderr, "Failed to init video! %s", SDL_GetError()); return 1; }; - + + // Setup window and renderer float main_scale = SDL_GetDisplayContentScale(SDL_GetPrimaryDisplay()); SDL_WindowFlags window_flags = SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIDDEN | SDL_WINDOW_HIGH_PIXEL_DENSITY; SDL_Window* window = NULL; @@ -29,19 +30,19 @@ int main() { SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED); SDL_ShowWindow(window); - // Setup Dear ImGui context - //IMGUI_CHECKVERSION(); + // Setup Dear ImGui context igCreateContext(NULL); ImGuiIO* io = igGetIO(); (void)io; - io->ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls - io->ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls + io->ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; + io->ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Setup Dear ImGui style igStyleColorsDark(NULL); //igStyleColorsLight(NULL); + // Setup scaling ImGuiStyle* style = igGetStyle(); - ImGuiStyle_ScaleAllSizes(style, main_scale); // Bake a fixed style scale. (until we have a solution for dynamic style scaling, changing this requires resetting Style + calling this again) + ImGuiStyle_ScaleAllSizes(style, main_scale); style->FontScaleDpi = main_scale; // Set initial font scale. (using io.ConfigDpiScaleFonts=true makes this unnecessary. We leave both here for documentation purpose) io->ConfigDpiScaleFonts = true; // [Experimental] Automatically overwrite style.FontScaleDpi in Begin() when Monitor DPI changes. This will scale fonts but _NOT_ scale sizes/padding for now. io->ConfigDpiScaleViewports = true; // [Experimental] Scale Dear ImGui and Platform Windows when Monitor DPI changes. @@ -49,7 +50,6 @@ int main() { // Setup Platform/Renderer backends ImGui_ImplSDL3_InitForSDLRenderer(window, renderer); ImGui_ImplSDLRenderer3_Init(renderer); - // finish loading data // Our state bool show_demo_window = true; @@ -87,7 +87,7 @@ int main() { continue; } - // Start the Dear ImGui frame + // Setup Dear ImGui frame SDL_SetRenderDrawColorFloat(renderer, clear_color.x, clear_color.y, clear_color.z, clear_color.w); SDL_RenderClear(renderer); ImGui_ImplSDLRenderer3_NewFrame(); @@ -103,19 +103,19 @@ int main() { static float f = 0.0f; static int counter = 0; - igBegin("Hello, world!", NULL, 0); // Create a window called "Hello, world!" and append into it. + igBegin("Hello, world!", NULL, 0); // Create a window called "Hello, world!" and append into it. - igText("This is some useful text."); // Display some text (you can use a format strings too) - igCheckbox("Demo Window", &show_demo_window); // Edit bools storing our window open/close state + igText("This is some useful text."); // Display some text (you can use a format strings too) + igCheckbox("Demo Window", &show_demo_window); // Edit bools storing our window open/close state igCheckbox("Another Window", &show_another_window); - igSliderFloat("float", &f, 0.0f, 1.0f, "%.3f", 0); // Edit 1 float using a slider from 0.0f to 1.0f + igSliderFloat("float", &f, 0.0f, 1.0f, "%.3f", 0); // Edit 1 float using a slider from 0.0f to 1.0f igColorEdit4("clear color", (float*)&clear_color, 0); // Edit 3 floats representing a color ImVec2 buttonSize; buttonSize.x = 0; buttonSize.y = 0; - if (igButton("Button", buttonSize)) // Buttons return true when clicked (most widgets return true when edited/activated) + if (igButton("Button", buttonSize)) // Buttons return true when clicked (most widgets return true when edited/activated) counter++; igSameLine(0.0f, -1.0f); igText("counter = %d", counter);