XNA Creators Club Online
Page 1 of 1 (8 items)
Sort Posts: Previous Next

how to render to texture?

Last post 10/17/2007 5:55 AM by Coding4Fun. 7 replies.
  • 10/16/2007 6:05 PM

    how to render to texture?

    can anybody tell me how I'm able to render to a texture instead of using the back buffer? thx!
  • 10/16/2007 7:14 PM In reply to

    Re: how to render to texture?

    You need to create a 2D texture with D3D10_BIND_RENDER_TARGET and D3D10_BIND_SHADER_RESOURCE. Then you can create a render target view for this resource and use it like the render target view that you have created for the back buffer.

    You can find an example of this in the MotionBlur sample.

  • 10/16/2007 7:36 PM In reply to

    Re: how to render to texture?

    I created a ID3D10Texture2D object and a ID3D10RenderTargetView. on rendering I'm doing the following:

    pDevice->OMGetRenderTargets(1, &pFirstRenderTargetView, NULL);
    pDevice->OMSetRenderTargets(1, &pSecondRenderTargetView, NULL);
    pDevice->ClearRenderTargets(pSecondRenderTarget, D3DXCOLOR(0.0f, 0.0f, 0.0f, 0.0f));

    pFont->DrawText(...);

    pDevice->OMGetRenderTargets(1, &pSecondRenderTargetView, NULL);
    pDevice->OMSetRenderTargets(1, &pFirstRenderTargetView, NULL);

    ID3D10Resource* pResource = NULL;
    pSecondRenderTargetView->GetResource(&pResource);

    ID3D10Texture2D* pTexture = NULL;
    pResource->QueryInterface(__uuidof(ID3D10Texture2D), (LPVOID*)&pTexture);

    //Creating D3D10_SHADER_RESOURCE_VIEW_DESC
    pDevice->CreateShaderResourceView(pTexture, &pSrvDesc, &pSecondShaderResourceView);

    //Drawing pSecondShaderResourceView as sprite

    but the problem is that there is no text visible

  • 10/16/2007 8:05 PM In reply to

    Re: how to render to texture?

    You don’t create a new shader resource view every time you render a frame?

     I assume you already have enabled the debug layer and checked that it reports no errors.

    As your back buffer and the texture have properly different sizes you should set the viewport.

    Beside of this you should give PIX a try. If you have a nvidia GF8 NVPerfHUD is useful too.

  • 10/16/2007 8:10 PM In reply to

    Re: how to render to texture?

    I'm not sure if i have to create a new shader resource view every time...
  • 10/16/2007 8:17 PM In reply to

    Re: how to render to texture?

    You shouldn’t do this. Creating resources and views are somewhat expensive operations. It is bad to do this over and over again.

  • 10/17/2007 1:51 AM In reply to

    Re: how to render to texture?

    You might try utilizing the BasicHLSL10 demo from the DirectX August SDK and then utilize that DXUT code sinc eit sets up a nice viewport with controls etc. and then strip out and replace what you don't need with your code.  It helps when debugging rendering issues such as lighting and such.  That may be a step back from what you are doing, but it's helped me out a few times.

     

    Regards,

    Jeff

  • 10/17/2007 5:55 AM In reply to

    Re: how to render to texture?

    ok i found the error and I saw that it isn't necessary to create the SRV in every frame...
Page 1 of 1 (8 items) Previous Next