@@ -47,9 +47,15 @@ void Core::SwapchainCreate11(ID3D11Device5* device, ID3D11DeviceContext* context
4747 screenHeight_ = desc->BufferDesc .Height ;
4848 firstFrame_ = true ;
4949
50+ dxSwapChain = swc;
51+ pD11Device = device;
52+ pD11DeviceContext = context;
53+
5054 ImGui_ImplDX11_Init (device, context);
5155}
5256
57+ ID3D11RenderTargetView* pD11RenderTargetView = nullptr ;
58+
5359void Core::DrawOver11 ()
5460{
5561 if (firstFrame_)
@@ -58,14 +64,35 @@ void Core::DrawOver11()
5864 }
5965 else
6066 {
67+ // TODO: took this part from https://github.com/lguilhermee/Discord-DX11-Overlay-Hook/
68+ // maybe it is bad idea to recreate RTVs every frame? need to deal with this later on
69+ ID3D11Texture2D* renderTargetTexture = nullptr ;
70+ if (!pD11RenderTargetView)
71+ {
72+ if (SUCCEEDED (dxSwapChain->GetBuffer (0 , __uuidof (ID3D11Texture2D), reinterpret_cast <LPVOID*>(&renderTargetTexture))))
73+ {
74+ pD11Device->CreateRenderTargetView (renderTargetTexture, nullptr , &pD11RenderTargetView);
75+ renderTargetTexture->Release ();
76+ }
77+ }
78+
6179 ImGui_ImplDX11_NewFrame ();
6280 ImGui_ImplWin32_NewFrame ();
6381 ImGui::NewFrame ();
6482
6583 // this sends event to all other addons to draw their UI
6684 SendDrawEvent ();
6785
86+ pD11DeviceContext->OMSetRenderTargets (1 , &pD11RenderTargetView, nullptr );
6887 ImGui::Render ();
88+
89+ // Release and free resources to setup again on the next loop.
90+ if (pD11RenderTargetView)
91+ {
92+ pD11RenderTargetView->Release ();
93+ pD11RenderTargetView = nullptr ;
94+ }
95+
6996 ImGui_ImplDX11_RenderDrawData (ImGui::GetDrawData ());
7097 }
7198}
0 commit comments