However I don't understand how to do it.
Class Declaration of the DX11 Engine is:
ID3D11Device* m_pDevice;
ID3D11DeviceContext* m_pDeviceContext;
IDXGISwapChain* m_pSwapChain;
And the Engine Render Function is as follows:
m_D2DEngine is what I wanted to take care of the Rendering of a queue of texts.
void DX11Engine::Render()
{
m_pDeviceContext->ClearRenderTargetView(m_pBackbuffer, D3DXCOLOR(0.0f, 0.2f, 0.4f, 1.0f));
m_pDeviceContext->ClearDepthStencilView(m_pDepthStencilView, D3D11_CLEAR_DEPTH, 1.0f, 0);
m_pScene->Render();
m_D2DEngine.Render();
m_pSwapChain->Present(0, 0);
}
]
Render Function in the D2DEngine looks as follows:
ID3D10Device* m_pDevice;
D2D Needed a D3D10Device
void Direct2DEngine::Render()
{
HRESULT hr = S_OK;
m_pBackBuffer->BeginDraw();
m_pBackBuffer->SetTransform(D2D1::Matrix3x2F::Identity());
D2D1_SIZE_F rtSize = m_pBackBuffer->GetSize();
ID2D1SolidColorBrush* pBackBufferTextBrush = NULL;
hr = m_pBackBuffer->CreateSolidColorBrush(
D2D1::ColorF(D2D1::ColorF::Red),
&pBackBufferTextBrush
);
for (unsigned int index = 0; index < m_vecTextToRender.size(); index++)
{
m_pBackBuffer->DrawText(
StringToWideString(m_vecTextToRender[index].m_strText).c_str(),
m_vecTextToRender[index].m_strText.size(),
m_pTextFormat,
D2D1::RectF(0.0f, 0.0f, rtSize.width, rtSize.height),
pBackBufferTextBrush
);
}
hr = m_pBackBuffer->EndDraw();
if (SUCCEEDED(hr) && m_pRenderTarget)
{
// Swap chain will tell us how big the back buffer is
DXGI_SWAP_CHAIN_DESC swapDesc;
hr = m_pSwapChain->GetDesc(&swapDesc);
if (SUCCEEDED(hr))
{
m_pDevice->ClearDepthStencilView(
m_pDepthStencilView,
D3D10_CLEAR_DEPTH,
1,
0
);
if (SUCCEEDED(hr))
{
m_pDiffuseVariableNoRef->SetResource(NULL);
m_pTechniqueNoRef->GetPassByIndex(0)->Apply(0);
// Draw the D2D content into a D3D surface.
hr = RenderD2DContentIntoSurface();
}
if (SUCCEEDED(hr))
{
m_pDiffuseVariableNoRef->SetResource(m_pTextureResourceView);
// Update variables that change once per frame.
m_pWorldVariableNoRef->SetMatrix((float*)&m_WorldMatrix);
// Set the index buffer.
m_pDevice->IASetIndexBuffer(m_pFacesIndexBuffer, DXGI_FORMAT_R16_UINT, 0);
// Render the scene
m_pTechniqueNoRef->GetPassByIndex(0)->Apply(0);
m_pDevice->DrawIndexed(
ARRAYSIZE(s_FacesIndexArray),
0,
0
);
// Draw some text using a red brush on top of everything
//if (m_pBackBuffer)
//{
//m_pBackBuffer->BeginDraw();
//m_pBackBuffer->SetTransform(D2D1::Matrix3x2F::Identity());
// Text format object will center the text in layout
//D2D1_SIZE_F rtSize = m_pBackBuffer->GetSize();
//ID2D1SolidColorBrush* pBackBufferTextBrush = NULL;
//hr = m_pBackBuffer->CreateSolidColorBrush(
// D2D1::ColorF(D2D1::ColorF::Red),
// &pBackBufferTextBrush
// );
//for (unsigned int index = 0; index < m_vecTextToRender.size(); index++)
//{
// m_pBackBuffer->DrawText(
// StringToWideString(m_vecTextToRender[index].m_strText).c_str(),
// m_vecTextToRender[index].m_strText.size(),
// m_pTextFormat,
// D2D1::RectF(0.0f, 0.0f, rtSize.width, rtSize.height),
// pBackBufferTextBrush
// );
//}
//hr = m_pBackBuffer->EndDraw();
//}
if (SUCCEEDED(hr))
{
hr = m_pSwapChain->Present(1, 0);
}
}
}
}
m_vecTextToRender.clear();
}
So my problem here is that it flicker betweens the rendered
1st: DX11 Picture - Blue background atm
2nd: D2DText - Black backround - Red Text
So how should I change the D2D Render function to draw it to my normal Picture?
I'm so unclear with everything since I had to create the D3D10Device also.