title: Directx9 surface to texture
body: <p>I want to capture my Backbuffer into my LPDIRECT3DSURFACE9 and then copy the surface into my IDirect3DTexture9 finally use that texture as my object skin. I wrote the codes but just received black pixels.</p>
  
  <pre><code>IDirect3DTexture9* texture;
  LPDIRECT3DSURFACE9 pd3dsBack = NULL;
  
  void init()//init point
  {
  
      D3DXCreateTexture(g_pd3dDevice, 640, 480, D3DUSAGE_DYNAMIC,
          0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &amp;texture);
  
  }
  
  void render()//render point
  {
  
      g_pd3dDevice-&gt;BeginScene();
  
      g_pd3dDevice-&gt;Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
          D3DCOLOR_COLORVALUE(0.0f, 1.0f, 0.0f, 1.0f), 1.0f, 0);
  
      //my scene (1) 3d objects codes for draw.
  
      g_pd3dDevice-&gt;EndScene();
  
      //now try to get back-buffer into surface
  
      g_pd3dDevice-&gt;GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &amp;pd3dsBack);
  
  
      //i add this Save section to ensure the backbuffer data received complete and work.(it was ok and save complete true picture of Scene(1) ).
  
      D3DXSaveSurfaceToFileA("BackbufferImage.BMP", D3DXIFF_BMP, pd3dsBack, NULL, NULL);
  
  
      //this line put surface into my texture ; if u think this way is false please give me a simple code to fill texture by surface.
  
      texture-&gt;GetSurfaceLevel(0, &amp;pd3dsBack);
  
      pd3dsBack-&gt;Release();//release my surface
  
  
                           //scene(2)
      g_pd3dDevice-&gt;BeginScene();
  
      g_pd3dDevice-&gt;Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
          D3DCOLOR_COLORVALUE(1.0f, 0.0f, 0.0f, 1.0f), 1.0f, 0);
  
      //now render my scene(2) and useing the texture object for draw it as skin of my 3d     object
      g_pd3dDevice-&gt;SetTexture(0, texture);
  
      g_pd3dDevice-&gt;EndScene();
  
  
      g_pd3dDevice-&gt;Present(NULL, NULL, NULL, NULL);
  
  }
  </code></pre>