Skip to main content

 none
Show ID3D11Texture2D on Screen RRS feed

  • Question

  • Hi, I have an RGBA ID3D11Texture2D that I want to display on screen in an application window that I create. I've followed relevant tutorials about creating a swap chain, and render target views, but I can't figure out how to actually make my texture show up on the screen. I tried to get the back buffer as an ID3D11Texture2D from the swap chain and then copy my texture into it using CopyResource, but that didn't work. Any ideas?

    Thanks!


    Abhishek Bhargava


    • Edited by abharga2354 Sunday, August 25, 2019 5:28 AM
    Sunday, August 25, 2019 4:22 AM

All replies

  • Hi,

    The sample code for creating and binding a complete render target view is given below:

    ID3D11RenderTargetView* backBufferTarget_; 
        ID3D11Texture2D* backBufferTexture; 
    
        result = swapChain_->GetBuffer( 0, __uuidof( ID3D11Texture2D ), ( LPVOID* )&backBufferTexture ); 
    
        if( FAILED( result ) ) 
            { 
            DXTRACE_MSG( "Failed to get the swap chain back buffer!" ); 
            return false; 
        } 
    
        result = d3dDevice_->CreateRenderTargetView( backBufferTexture, 0, &backBufferTarget_ ); 
    
        if( backBufferTexture ) 
            backBufferTexture->Release( ); 
    
        if( FAILED( result ) ) 
        { 
            DXTRACE_MSG( "Failed to create the render target view!" ); 
            return false; 
        } 
    
        d3dContext_->OMSetRenderTargets( 1, &backBufferTarget_, 0 );

    Maybe you forget the OMSetRenderTargets(). 

    For more detail, you can refer to sample code of Direcx11 Book.

     

    Best regards,

    Jeffrey


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, August 26, 2019 8:24 AM