Browse Source

Add files for DearImGui in case we want to use it.

Godzil 1 year ago
parent
commit
c0c582e093
8 changed files with 57 additions and 0 deletions
  1. 6 0
      .gitmodules
  2. 1 0
      CMakeLists.txt
  3. 32 0
      external/cmake/BuildImGui.cmake
  4. 1 0
      external/imgui
  5. 1 0
      external/imgui_sdl
  6. 2 0
      source/CMakeLists.txt
  7. 7 0
      source/app.cpp
  8. 7 0
      source/graphics.cpp

+ 6 - 0
.gitmodules

@@ -0,0 +1,6 @@
+[submodule "external/imgui"]
+	path = external/imgui
+	url = https://github.com/ocornut/imgui.git
+[submodule "external/imgui_sdl"]
+	path = external/imgui_sdl
+	url = https://github.com/Tyyppi77/imgui_sdl.git

+ 1 - 0
CMakeLists.txt

@@ -6,6 +6,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/external/cmake ${CMAKE_MODULE_
 project("PhysicEngine")
 
 include(GetGitRevisionDescription)
+include(BuildImGui)
 
 git_describe(VERSION --tags --dirty=-dirty)
 

+ 32 - 0
external/cmake/BuildImGui.cmake

@@ -0,0 +1,32 @@
+cmake_minimum_required(VERSION 3.1)
+
+include(ExternalProject)
+
+set(CMAKE_CXX_STANDARD 17)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+set(CMAKE_CXX_EXTENSIONS OFF)
+
+find_package(SDL2 REQUIRED)
+set(SDL2_INCDIR ${SDL2_INCLUDE_DIR} ${SDL2_IMAGE_INCLUDE_DIR} ${SDL2_TTF_INCLUDE_DIR} ${SDL2_MIXER_INCLUDE_DIR})
+
+add_library(ImGui STATIC)
+target_include_directories(ImGui PUBLIC ${SDL2_INCDIR})
+target_include_directories(ImGui PUBLIC external/imgui)
+target_include_directories(ImGui PUBLIC external/imgui/backends)
+
+file(GLOB ImG_SOURCES external/imgui/*.cpp external/imgui/backends/imgui_impl_sdl.cpp)
+file(GLOB ImG_HEADERS external/imgui/*.h external/imgui/backends/imgui_impl_sdl.h)
+
+target_sources(ImGui PRIVATE ${ImG_SOURCES} ${ImG_HEADERS})
+
+
+add_library(ImGuiSDL STATIC)
+message("SDL Dir: ${SDL2_INCDIR}")
+target_include_directories(ImGuiSDL PUBLIC ${SDL2_INCDIR})
+target_include_directories(ImGuiSDL PUBLIC external/imgui_sdl)
+target_include_directories(ImGuiSDL PUBLIC external/imgui)
+
+set(ImGSDL_SOURCES external/imgui_sdl/imgui_sdl.cpp)
+file(GLOB ImGSLD_HEADERS external/imgui_sdl/*.h)
+
+target_sources(ImGuiSDL PRIVATE ${ImGSDL_SOURCES} ${ImGSDL_HEADERS})

+ 1 - 0
external/imgui

@@ -0,0 +1 @@
+Subproject commit 65c4c0a490f64e7929a63c43be05748b34ec6228

+ 1 - 0
external/imgui_sdl

@@ -0,0 +1 @@
+Subproject commit ec9f06b02125b4427a5157cce06b344fb435776d

+ 2 - 0
source/CMakeLists.txt

@@ -16,3 +16,5 @@ target_include_directories(physicengine PUBLIC include/)
 target_sources(physicengine PRIVATE ${GE_SOURCES} ${GE_HEADERS})
 target_include_directories(physicengine PUBLIC ${SDL2_INCDIR})
 target_link_libraries(physicengine ${SDL2_LIBS})
+target_link_libraries(physicengine ImGui)
+target_link_libraries(physicengine ImGuiSDL)

+ 7 - 0
source/app.cpp

@@ -8,6 +8,9 @@
  */
 #include <app.h>
 #include <graphics.h>
+#include <imgui.h>
+#include <imgui_sdl.h>
+#include <imgui_impl_sdl.h>
 
 void application::parseParameters(int argc, char *argv[])
 {
@@ -24,6 +27,9 @@ void application::input()
     SDL_Event event;
     while(SDL_PollEvent(&event))
     {
+        //ImGui_ImplSDL2_ProcessEvent(&event);
+        //ImGuiIO &io = ImGui::GetIO();
+
         switch(event.type)
         {
         case SDL_QUIT:
@@ -50,6 +56,7 @@ void application::render()
     graphics::clearScreen(0xFF056263);
     graphics::draw::fillCircle(200, 200, 40, 0xFFFFFFFF);
     graphics::draw::text(10, 10, graphics::makeColour(255, 12, 98), "Hello world!");
+
     graphics::renderFrame();
 }
 

+ 7 - 0
source/graphics.cpp

@@ -14,6 +14,10 @@
 #include <SDL_ttf.h>
 #include <SDL2_gfxPrimitives.h>
 
+#include <imgui.h>
+#include <imgui_sdl.h>
+#include <imgui_impl_sdl.h>
+
 #include <logger.h>
 
 #include <graphics.h>
@@ -68,6 +72,9 @@ bool graphics::openWindow()
 
     SDL_SetWindowFullscreen(graphics::window, SDL_WINDOW_FULLSCREEN);
 
+    ImGui::CreateContext();
+    ImGuiSDL::Initialize(graphics::renderer, graphics::windowWidth, graphics::windowHeight);
+
     return true;
 }