build and use imgui from externals, make the imgui demo work
This commit is contained in:
parent
6dcb5d8e8a
commit
31aa3f049e
4 changed files with 51 additions and 16 deletions
15
external/CMakeLists.txt
vendored
15
external/CMakeLists.txt
vendored
|
@ -2,3 +2,18 @@ option(NNG_SETSTACKSIZE "Use rlimit for thread stack size" ON)
|
||||||
set(NNG_TESTS OFF)
|
set(NNG_TESTS OFF)
|
||||||
set(NNG_ENABLE_NNGCAT OFF)
|
set(NNG_ENABLE_NNGCAT OFF)
|
||||||
add_subdirectory(nng)
|
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)
|
||||||
|
|
4
external/imgui/imconfig.h
vendored
4
external/imgui/imconfig.h
vendored
|
@ -27,8 +27,8 @@
|
||||||
//#define IMGUI_API __declspec( dllimport )
|
//#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.
|
//---- 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_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_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.
|
//---- 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.
|
// 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.
|
||||||
|
|
|
@ -20,12 +20,9 @@ find_package(SDL2 REQUIRED)
|
||||||
|
|
||||||
add_executable(doompanning doompanning.cc)
|
add_executable(doompanning doompanning.cc)
|
||||||
target_compile_features(doompanning PRIVATE cxx_std_17)
|
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
|
target_link_libraries(doompanning
|
||||||
PRIVATE dp_common
|
PRIVATE dp_common
|
||||||
#PRIVATE ${IMGUI_LIBRARIES}
|
PRIVATE imgui
|
||||||
PRIVATE SDL2::SDL2-static
|
|
||||||
)
|
)
|
||||||
|
|
||||||
add_executable(doomsim doomsim.cc)
|
add_executable(doomsim doomsim.cc)
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <nng/nng.h>
|
#include <nng/nng.h>
|
||||||
|
|
||||||
//#include <imgui.h>
|
#include <imgui.h>
|
||||||
//#include <backends/imgui_impl_sdl.h>
|
#include <backends/imgui_impl_sdl.h>
|
||||||
|
#include <backends/imgui_impl_sdlrenderer.h>
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
|
|
||||||
#include "dp_common.h"
|
#include "dp_common.h"
|
||||||
|
@ -10,7 +11,7 @@
|
||||||
|
|
||||||
void dp_sdl_fatal(const char *const msg)
|
void dp_sdl_fatal(const char *const msg)
|
||||||
{
|
{
|
||||||
log_fatal("%s: %s", SDL_GetError());
|
log_fatal("%s: %s", msg, SDL_GetError());
|
||||||
abort();
|
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)
|
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;
|
bool done = false;
|
||||||
|
|
||||||
while (!done)
|
while (!done)
|
||||||
|
@ -25,11 +30,28 @@ int doom_controller_loop(nng_socket pubSock, nng_socket subSock, SDL_Window *win
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
while (SDL_PollEvent(&event))
|
while (SDL_PollEvent(&event))
|
||||||
{
|
{
|
||||||
|
ImGui_ImplSDL2_ProcessEvent(&event);
|
||||||
|
|
||||||
if (event.type == SDL_QUIT)
|
if (event.type == SDL_QUIT)
|
||||||
done = true;
|
done = true;
|
||||||
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE && event.window.windowID == SDL_GetWindowID(window))
|
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE && event.window.windowID == SDL_GetWindowID(window))
|
||||||
done = true;
|
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;
|
return 0;
|
||||||
|
@ -64,10 +86,11 @@ int main(int argc, char *argv[])
|
||||||
if (!renderer)
|
if (!renderer)
|
||||||
dp_sdl_fatal("SDL_CreateRenderer");
|
dp_sdl_fatal("SDL_CreateRenderer");
|
||||||
|
|
||||||
//IMGUI_CHECKVERSION();
|
IMGUI_CHECKVERSION();
|
||||||
//ImGui::CreateContext();
|
ImGui::CreateContext();
|
||||||
//ImGui::StyleColorsDark();
|
ImGui::StyleColorsDark();
|
||||||
//ImGui_ImplSDL2_InitForSDLRenderer(window);
|
ImGui_ImplSDL2_InitForSDLRenderer(window, renderer);
|
||||||
|
ImGui_ImplSDLRenderer_Init(renderer);
|
||||||
|
|
||||||
int ret = doom_controller_loop(pubSock, subSock, window, renderer);
|
int ret = doom_controller_loop(pubSock, subSock, window, renderer);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue