diff --git a/enginecustom/Systemclass.cpp b/enginecustom/Systemclass.cpp index 2f0b18e..5d65897 100644 --- a/enginecustom/Systemclass.cpp +++ b/enginecustom/Systemclass.cpp @@ -1,4 +1,6 @@ #include "systemclass.h" +#include +extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); SystemClass::SystemClass() { @@ -36,12 +38,22 @@ bool SystemClass::Initialize() // Create and initialize the application class object. This object will handle rendering all the graphics for this application. m_Application = new ApplicationClass; + // Initialize the application object. + result = m_Application->Initialize(screenWidth, screenHeight, m_hwnd); if (!result) { return false; } + // Initialize imgui + IMGUI_CHECKVERSION(); + ImGui::CreateContext(); + ImGuiIO& io = ImGui::GetIO(); + + ImGui_ImplWin32_Init(m_hwnd); + ImGui_ImplDX11_Init(m_Application->GetDirect3D()->GetDevice(), m_Application->GetDirect3D()->GetDeviceContext()); + return true; } @@ -62,6 +74,11 @@ void SystemClass::Shutdown() m_Input = 0; } + // Shutdown imgui + ImGui_ImplDX11_Shutdown(); + ImGui_ImplWin32_Shutdown(); + ImGui::DestroyContext(); + // Shutdown the window. ShutdownWindows(); @@ -111,6 +128,7 @@ void SystemClass::Run() bool SystemClass::Frame() { bool result; + float value = 0.0f; // Check if the user pressed escape and wants to exit the application. @@ -119,6 +137,19 @@ bool SystemClass::Frame() return false; } + ImGui_ImplDX11_NewFrame(); + ImGui_ImplWin32_NewFrame(); + ImGui::NewFrame(); + + //ImGui Widget + ImGui::Begin("Khaotic Engine", NULL); + ImGui::Text("Salam"); + ImGui::SliderFloat("Slider", &value, 0.0f, 1.0f); + ImGui::End(); + + ImGui::Render(); + ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData()); + // Do the frame processing for the application class object. result = m_Application->Frame(); if (!result) @@ -131,6 +162,12 @@ bool SystemClass::Frame() LRESULT CALLBACK SystemClass::MessageHandler(HWND hwnd, UINT umsg, WPARAM wparam, LPARAM lparam) { + + if (ImGui_ImplWin32_WndProcHandler(hwnd, umsg, wparam, lparam)) + { + return true; + } + switch (umsg) { // Check if a key has been pressed on the keyboard. diff --git a/enginecustom/applicationclass.cpp b/enginecustom/applicationclass.cpp index a28c4a7..0ab0b3a 100644 --- a/enginecustom/applicationclass.cpp +++ b/enginecustom/applicationclass.cpp @@ -152,4 +152,9 @@ bool ApplicationClass::Render() m_Direct3D->EndScene(); return true; +} + +D3DClass* ApplicationClass::GetDirect3D() +{ + return m_Direct3D; } \ No newline at end of file diff --git a/enginecustom/applicationclass.h b/enginecustom/applicationclass.h index 8a74383..3620a8a 100644 --- a/enginecustom/applicationclass.h +++ b/enginecustom/applicationclass.h @@ -25,6 +25,7 @@ public: ApplicationClass(); ApplicationClass(const ApplicationClass&); ~ApplicationClass(); + D3DClass* GetDirect3D(); bool Initialize(int, int, HWND); void Shutdown(); diff --git a/enginecustom/enginecustom.vcxproj b/enginecustom/enginecustom.vcxproj index 3c74b8c..b72f17c 100644 --- a/enginecustom/enginecustom.vcxproj +++ b/enginecustom/enginecustom.vcxproj @@ -24,6 +24,12 @@ + + + + + + @@ -145,6 +151,7 @@ true _DEBUG;_WINDOWS;%(PreprocessorDefinitions) true + $(SolutionDir)enginecustom\include\backends;$(SolutionDir)enginecustom\include;%(AdditionalIncludeDirectories) Windows diff --git a/enginecustom/imgui.ini b/enginecustom/imgui.ini new file mode 100644 index 0000000..1bea7cb --- /dev/null +++ b/enginecustom/imgui.ini @@ -0,0 +1,8 @@ +[Window][Debug##Default] +Pos=60,60 +Size=400,400 + +[Window][Khaotic Engine] +Pos=60,60 +Size=51,48 + diff --git a/enginecustom/systemclass.h b/enginecustom/systemclass.h index 4eb1d8d..e50f4c3 100644 --- a/enginecustom/systemclass.h +++ b/enginecustom/systemclass.h @@ -5,6 +5,9 @@ #include #include "inputclass.h" #include "applicationclass.h" +#include "imgui.h" +#include "imgui_impl_win32.h" +#include "imgui_impl_dx11.h" class SystemClass {