title: RenderTargetView <-> Texture
body: <p>I found <a href="http://www.braynzarsoft.net/index.php?p=D3D11RTT" rel="nofollow">this</a> tutorial, i follow it and i create the class DirectX</p>
  
  <pre><code>class DirectX
  {
  private:
  D3D_DRIVER_TYPE DriverType;
  D3D_FEATURE_LEVEL FeatureLevel;
  public:
  int InitDirectX(HWND &amp;hwnd, WinDesc &amp;wd)
  {
      HRESULT result;
      RECT dimensions;
      GetClientRect( hwnd, &amp;dimensions );
      int width=dimensions.right-dimensions.left;
      int height=dimensions.bottom-dimensions.top;
      D3D_DRIVER_TYPE driverTypes[]=
      {
          D3D_DRIVER_TYPE_HARDWARE, 
          D3D_DRIVER_TYPE_WARP, 
          D3D_DRIVER_TYPE_SOFTWARE
      };
      unsigned int totalDriverTypes=ARRAYSIZE(driverTypes);
      D3D_FEATURE_LEVEL featureLevels[]=
      {
          D3D_FEATURE_LEVEL_11_0,
          D3D_FEATURE_LEVEL_10_1,
          D3D_FEATURE_LEVEL_10_0
      };
      unsigned int totalFeatureLevels = ARRAYSIZE( featureLevels );
      DXGI_SWAP_CHAIN_DESC swapChainDesc;
      ZeroMemory(&amp;swapChainDesc,sizeof(swapChainDesc));
      swapChainDesc.BufferCount=1;
      swapChainDesc.BufferDesc.Width=width;
      swapChainDesc.BufferDesc.Height=height;
      swapChainDesc.BufferDesc.Format=DXGI_FORMAT_R8G8B8A8_UNORM;
      swapChainDesc.BufferDesc.RefreshRate.Numerator=60;
      swapChainDesc.BufferDesc.RefreshRate.Denominator=1;
      swapChainDesc.BufferUsage=DXGI_USAGE_RENDER_TARGET_OUTPUT;
      swapChainDesc.OutputWindow=hwnd;
      swapChainDesc.Windowed=1;
      swapChainDesc.SampleDesc.Count=1;
      swapChainDesc.SampleDesc.Quality=0;
      for(int driver=0;driver&lt;totalDriverTypes;++driver)
      {
          result = D3D11CreateDeviceAndSwapChain( 0, driverTypes[driver], 0,
                  0, featureLevels, totalFeatureLevels,
                  D3D11_SDK_VERSION, &amp;swapChainDesc, &amp;SwapChain,
                  &amp;Device, &amp;FeatureLevel, &amp;Context );
          if( SUCCEEDED( result ) )
          {
          D3D_DRIVER_TYPE driverType_ = driverTypes[driver];
          break;
          }
      }
  
      }
      D3D11_TEXTURE2D_DESC textureDesc;
      D3D11_RENDER_TARGET_VIEW_DESC renderTargetViewDesc;
      D3D11_SHADER_RESOURCE_VIEW_DESC shaderResourceViewDesc;
      ZeroMemory(&amp;textureDesc, sizeof(textureDesc));
      textureDesc.Width = width;
      textureDesc.Height = height;
      textureDesc.MipLevels = 1;
      textureDesc.ArraySize = 1;
      textureDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
      textureDesc.SampleDesc.Count = 1;
      textureDesc.Usage = D3D11_USAGE_DEFAULT;
      textureDesc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
      textureDesc.CPUAccessFlags = 0;
      textureDesc.MiscFlags = 0;
      result=Device-&gt;CreateTexture2D(&amp;textureDesc, NULL, &amp;backBuffer);
  
      renderTargetViewDesc.Format = textureDesc.Format;
      renderTargetViewDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
      renderTargetViewDesc.Texture2D.MipSlice = 0;
      result=Device-&gt;CreateRenderTargetView(backBuffer, &amp;renderTargetViewDesc, &amp;RenderTargetView);
  
      shaderResourceViewDesc.Format = textureDesc.Format;
      shaderResourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
      shaderResourceViewDesc.Texture2D.MostDetailedMip = 0;
      shaderResourceViewDesc.Texture2D.MipLevels = 1;
      result=Device-&gt;CreateShaderResourceView(backBuffer, &amp;shaderResourceViewDesc, &amp;shaderResourceView);
  
      float color[4]={1,1,0,0};
      Context-&gt;ClearRenderTargetView(RenderTargetView,color);
      Context-&gt;OMSetRenderTargets(1,&amp;RenderTargetView,0);
  }
  };
  </code></pre>
  
  <p>When i run it it get no error put when i call SwapChain->Present(0,0) nothing is displayed althought the renderTargetView should to be yellow.
  Why?? I cannot found the error. </p>
  
  <p>PS if i create a renderTargetView with this code:</p>
  
  <pre><code>ID3D11Texture2D* backBufferTexture;
  result = SwapChain-&gt;GetBuffer( 0, __uuidof( ID3D11Texture2D ),
                      ( LPVOID* )&amp;backBufferTexture );
  result = Device-&gt;CreateRenderTargetView( backBufferTexture, 0,
              &amp;RenderTargetView );
  </code></pre>
  
  <p>all works;
  and in my code i check all the "result" values;</p>
  
  <p>2°
  this is code of the sprite i want render:
  Init()//init vertex buffer, index buffer, texture, matrix....
  the render functioon is this:</p>
  
  <pre><code>C-&gt;OMSetRenderTargets(1,&amp;RT1,0);
  C-&gt;Update(...)// matrix to sent vertex shader, set texture, vertex, buffer....
  C-&gt;Draw(6,0)//draw the sprite;
  </code></pre>
  
  <p>It should render a sprite(ex. a ball) on RT1 then :</p>
  
  <pre><code>C-&gt;OMSetRenderTargets(1,&amp;RT,0);
  RT1-&gt;Update() //like the texture;
  RT1-&gt;Draw(6,0)
  ...
  Swapchain-&gt;present(1,0);
  </code></pre>
  
  <p>The RT1 is displayed(ex. if i have clear it with blue there is a blue shape on the screen i can translate, scale and rotate) but not the ball(i have render on RT1);
  but if i render the ball without set RT1 as renderTargetView the ball is correct displayed</p>