locked
Mixing 3D and 2D

    Question

  • I'm having a major issue with rendering a 3D mesh and then rendering 2D on top of it. The problem seems to be different every time I change the code in order to solve it.  The problem only occurs when I render both 3D and then 2D, just rendering any one will not cause the issue. First, I render a 3D mesh, then I render a 2D sprite on top of it.  The game will draw 1 - 2 frames, and then the entire screen will turn white, and the game will crash. An exception pops up and the Windows Action center tells me that the display driver stopped responding and then recovered itself.

    Here's my code:

    void BTGame::Draw() { //Game::Draw();

    const float midnightBlue[] = { 0.322f, 0.653f, 0.803f, 1.000f }; m_d3dContext->ClearRenderTargetView(m_d3dRenderTargetView.Get(), midnightBlue); m_d3dContext->ClearDepthStencilView(m_d3dDepthStencilView.Get(), D3D11_CLEAR_DEPTH, 1.0f, 0); m_d3dContext->OMSetRenderTargets(1, m_d3dRenderTargetView.GetAddressOf(), m_d3dDepthStencilView.Get()); RenderScene(); //RenderToTexture(); XMFLOAT4X4 identity = XMFLOAT4X4(); XMMATRIX identityM = XMMatrixIdentity(); XMStoreFloat4x4(&identity, identityM); m_spriteBatch->Begin(identity); XMFLOAT2 center = GameManager::m_screenManager->m_windowCenter; m_texture->m_scale = XMFLOAT2(0.5f, 0.5f); m_texture->Draw(m_spriteBatch, center.x, center.y); m_spriteBatch->End(); m_gameMan->Draw(); /*UINT resourceIndex = D3D11CalcSubresource(0, 0, 1); m_d3dContext->ResolveSubresource(m_backBuffer.Get(), resourceIndex, m_backBufferMsaa.Get(), resourceIndex, DXGI_FORMAT_B8G8R8A8_UNORM);*/ }

    void BTGame::RenderScene()
    {
    	// Set the vertex input layout.
    	m_d3dContext->IASetInputLayout(m_layout);
    
    	// Set the vertex and pixel shaders that will be used to render this triangle.
    	m_d3dContext->VSSetShader(m_vertexShader, NULL, 0);
    	m_d3dContext->PSSetShader(m_pixelShader, NULL, 0);
    
    	m_d3dContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
    
    	m_mesh->Render(m_d3dContext.Get(), m_cam);
    }

    Here's the exact exception:

    Unhandled exception at 0x000007FC468D811C (KernelBase.dll) in NAMEOFGAME.exe: 0x0000087D (parameters: 0x0000000000000000, 0x000000D28FAEC800, 0x000000D28FAEC820).

    It seems to occur at VSSetShader() under RenderScene, but the point that the game crashes will shift with different code.

    'm using a modified version of the SpriteBatch (modified to support animation and camera movement) in order to render the 2D artwork. Also, I'm running it on a Lenovo Yoga 13, with  8 gigs of ram, and an Intel I5 chip. It carried an ATI Radian 4000 HD video card, the drivers are up to date.

    Thanks to anyone who could help.


    [url=http://catalog.create.msdn.com/en-US/GameDetails.aspx?catalogEntryId=5cbacba6-05c2-4c33-9005-6cc80c8d5753&type=1]Bible Trivia Avatar Edition[/url], currently in review.


    Saturday, March 30, 2013 12:14 PM

All replies

  • Hello,

    Would you please provide us the whole codes to reproduce this issue,

    You can upload your project to SkyDrive
    http://skydrive.live.com/

    It is not necessary that you send out the whole of your project. We just need a simplest sample to reproduce the problem. You can remove any confidential information or business details from it.

    If you don't want to upload the sample code, you can try to get the paid support from https://getsupport.microsoft.com/

    Best regards,
    Jesse


    Jesse Jiang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, April 1, 2013 3:13 AM
    Moderator
  • After being forced to shear my code apart, I finally found the issue... The spritebatch uses a geometry shader in order to greatly speed up the draw time. After drawing to the spritebatch, the geometry shader needs to be reset to null.


    [url=http://catalog.create.msdn.com/en-US/GameDetails.aspx?catalogEntryId=5cbacba6-05c2-4c33-9005-6cc80c8d5753&type=1]Bible Trivia Avatar Edition[/url], currently in review.

    Tuesday, April 2, 2013 7:37 PM
  • What implementation of 'spritebatch' are you using?
    Tuesday, April 2, 2013 8:39 PM