I am trying to use DirectXTK for an easy way to render 2d font in a 3d engine.
I am getting very strange results, however.
Here is the code I am using for my render frame
void Graphics::RenderFrame()
{
//Clear our backbuffer to the updated color
const float bgColor[4] = { 0, 0, 1.0f, 1.0f };
m_d3d11DevCon->ClearRenderTargetView(m_renderTargetView, bgColor);
//Refresh the Depth/Stencil view
m_d3d11DevCon->ClearDepthStencilView(m_depthStencilView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
m_d3d11DevCon->PSSetShaderResources(0, 1, &m_testTexture); //set texture to use for pixel shader
m_d3d11DevCon->PSSetSamplers(0, 1, &m_samplerState); //set sampler state to use
//Draw the square for texture
m_d3d11DevCon->DrawIndexed(6, 0, 0);
//draw text
m_spriteBatch->Begin();
const wchar_t* output = L"Hello World";
XMVECTOR fontPos = XMVectorSet(0, 0, 0, 0);
m_font->DrawString(m_spriteBatch.get(), output,
fontPos, Colors::White, 0.f, g_XMZero, 2.0f);
m_spriteBatch->End();
//Present the backbuffer to the screen
m_swapChain->Present(0, 0);
}
If I comment out all of the code for drawing the text, this is the result I get where my 3d square is being drawn correctly with its texture.
If I leave the code for Begin/End'ing the sprite batch and drawing the text, this is the result I get where my square in 3d space is no longer visible, and the H in "Hello" seems to have something gone wrong with it.
If I only comment out the code to draw the string, but I leave the SpriteBatch->Begin / SpriteBatch->End calls, I get nothing on my screen, but I would expect to get the square with the texture on it.
Is it not possible to combine Direct3D draw calls while using the DirectXTK SpriteBatch? If this will not work does anyone have any good recommendations of routes to go for efficient text rendering in dx11?