diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index 8a32f41..990c237 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -1,4 +1,19 @@ option(NNG_SETSTACKSIZE "Use rlimit for thread stack size" ON) set(NNG_TESTS OFF) set(NNG_ENABLE_NNGCAT OFF) -add_subdirectory(nng) \ No newline at end of file +add_subdirectory(nng) + +find_package(SDL2 REQUIRED) + +add_library(imgui SHARED + imgui/imgui.cpp + imgui/imgui_demo.cpp + imgui/imgui_draw.cpp + imgui/imgui_tables.cpp + imgui/imgui_widgets.cpp + imgui/backends/imgui_impl_sdl.cpp + imgui/backends/imgui_impl_sdlrenderer.cpp +) + +target_include_directories(imgui PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/imgui) +target_link_libraries(imgui PUBLIC SDL2::SDL2) diff --git a/external/imgui/imconfig.h b/external/imgui/imconfig.h index ed26508..d1e1122 100644 --- a/external/imgui/imconfig.h +++ b/external/imgui/imconfig.h @@ -27,8 +27,8 @@ //#define IMGUI_API __declspec( dllimport ) //---- Don't define obsolete functions/enums/behaviors. Consider enabling from time to time after updating to avoid using soon-to-be obsolete function/names. -//#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS -//#define IMGUI_DISABLE_OBSOLETE_KEYIO // 1.87: disable legacy io.KeyMap[]+io.KeysDown[] in favor io.AddKeyEvent(). This will be folded into IMGUI_DISABLE_OBSOLETE_FUNCTIONS in a few versions. +#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS +#define IMGUI_DISABLE_OBSOLETE_KEYIO // 1.87: disable legacy io.KeyMap[]+io.KeysDown[] in favor io.AddKeyEvent(). This will be folded into IMGUI_DISABLE_OBSOLETE_FUNCTIONS in a few versions. //---- Disable all of Dear ImGui or don't implement standard windows/tools. // It is very strongly recommended to NOT disable the demo windows and debug tool during development. They are extremely useful in day to day work. Please read comments in imgui_demo.cpp. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c4621b8..6342d9c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -20,16 +20,13 @@ find_package(SDL2 REQUIRED) add_executable(doompanning doompanning.cc) target_compile_features(doompanning PRIVATE cxx_std_17) -#target_compile_options(doompanning PRIVATE ${IMGUI_CFLAGS}) -#target_include_directories(doompanning PRIVATE ${IMGUI_INCLUDE_DIRS}) target_link_libraries(doompanning PRIVATE dp_common - #PRIVATE ${IMGUI_LIBRARIES} - PRIVATE SDL2::SDL2-static + PRIVATE imgui ) add_executable(doomsim doomsim.cc) target_compile_features(doomsim PRIVATE cxx_std_17) target_link_libraries(doomsim PRIVATE dp_common - ) \ No newline at end of file +) diff --git a/src/doompanning.cc b/src/doompanning.cc index a418642..69582a1 100644 --- a/src/doompanning.cc +++ b/src/doompanning.cc @@ -1,8 +1,9 @@ #include #include -//#include -//#include +#include +#include +#include #include #include "dp_common.h" @@ -10,7 +11,7 @@ void dp_sdl_fatal(const char *const msg) { - log_fatal("%s: %s", SDL_GetError()); + log_fatal("%s: %s", msg, SDL_GetError()); abort(); } @@ -18,6 +19,10 @@ static const size_t NumDooms = 3; int doom_controller_loop(nng_socket pubSock, nng_socket subSock, SDL_Window *window, SDL_Renderer *renderer) { + bool show_demo_window = true; + bool show_another_window = false; + ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); + bool done = false; while (!done) @@ -25,11 +30,28 @@ int doom_controller_loop(nng_socket pubSock, nng_socket subSock, SDL_Window *win SDL_Event event; 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_ImplSDLRenderer_NewFrame(); + ImGui_ImplSDL2_NewFrame(); + ImGui::NewFrame(); + + if (show_demo_window) + ImGui::ShowDemoWindow(&show_demo_window); + + // Rendering + ImGui::Render(); + SDL_SetRenderDrawColor(renderer, (Uint8)(clear_color.x * 255), (Uint8)(clear_color.y * 255), (Uint8)(clear_color.z * 255), (Uint8)(clear_color.w * 255)); + SDL_RenderClear(renderer); + ImGui_ImplSDLRenderer_RenderDrawData(ImGui::GetDrawData()); + SDL_RenderPresent(renderer); } return 0; @@ -64,10 +86,11 @@ int main(int argc, char *argv[]) if (!renderer) dp_sdl_fatal("SDL_CreateRenderer"); - //IMGUI_CHECKVERSION(); - //ImGui::CreateContext(); - //ImGui::StyleColorsDark(); - //ImGui_ImplSDL2_InitForSDLRenderer(window); + IMGUI_CHECKVERSION(); + ImGui::CreateContext(); + ImGui::StyleColorsDark(); + ImGui_ImplSDL2_InitForSDLRenderer(window, renderer); + ImGui_ImplSDLRenderer_Init(renderer); int ret = doom_controller_loop(pubSock, subSock, window, renderer); @@ -130,4 +153,4 @@ int main(int argc, char *argv[]) break; } } - #endif \ No newline at end of file + #endif