   IDirect3DSurface9 and Occlusion
  Hey guys,I'm kind of new to DirectX (I have done some stuff with OpenGL) and I am a bit stuck.My main problem is that I have created a IDirect3DSurface9* and I'm able to display the video stream I want on it, I have also created many 3d cubes in the scene... the main problem I'm having though is that while the cubes should sometimes go in front of the video/IDirect3DSurface9 they never do. Basically I want to render the video in the background and possibly scale it to fit most of the screen (and 3d cubes in front of it). If you want more details let me know.... essentiallyI do a D3DXLoadSurfaceFromMemory (using a RECT).I also do some other stuff and  use LockRect and UnlockRect.Then I end with something like this:m_d3dDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &gBackBuf);m_d3dDevice->StretchRect(gImageSrc, NULL, gBackBuf, &destRect, D3DTEXF_NONE); Another confusion is that when I go full screen vs windowed mode... the image seems to be centered in full screen mode but in windowed mode it is just to the top left. Thanks   
  Perhaps my question is not very clear. Let me know if there is anything you guys need clarified. Thanks again.   ;  The problem is that you're using StretchRect. StretchRect won't respect anything in your depthstencil buffer, it will just do a dumb copy of one surface to another. What you should probably do instead is create a simple quad, and use that to draw your video surface as a texture. This will let you use depth buffering to make sure the cubes appear where they need to be, and you can make sure that the video always appears where you want it to.   ;  Thanks for your reply. I figured I would have to use a texture eventually... I just thought it would come at a performance hit... the video feed is live and it already has a bit of a lag.Anyway, if you could provide some example code of how I might go about converting from surface to texture that would be great.... or maybe some reference?Thanks   ;Quote:Original post by nobodytoldThanks for your reply. I figured I would have to use a texture eventually... I just thought it would come at a performance hit... the video feed is live and it already has a bit of a lag.Anyway, if you could provide some example code of how I might go about converting from surface to texture that would be great.... or maybe some reference?ThanksThere shouldn't be any performance hit since textures are just collections of surfaces, and internally the driver probably does StretchRect as a textured quad anyway.What you'll want to do is instead of just creating a surface, create a texture with IDirect3DDevice9::CreateTexture. Just create it with 1 mip level, and you can probably stick it in D3DPOOL_MANAGED. You may also want to try D3DPOOL_DEFAULT, with D3DUSAGE_DYNAMIC. Then when you need to copy the video data to the texture, just grab the top-level surface from the texture by calling IDirect3DTexture9::GetSurfaceLevel with Level = 0 and then you can use D3DXLoadSurfaceFromMemory.;  EDIT: I should mention I really want the surface to be the background to my scene... so it really just needs to be behind everything else instead of in front of it.I am still trying to figure this out.It seems that I HAVE to use a surface and the stretchrect.I'm using a 3d stereo API by Nividia:the basic process is explained here (slide #38):http://developer.download.nvidia.com/presentations/2009/GDC/GDC09-3DVision-The_In_and_Out.pdfI did it a lot of research to try to find people doing this with textures, I found a guy who uses textures but ultimately uses a surface in the end:http://www.mtbs3d.com/phpbb/viewtopic.php?f=60&t=4026That document mentions the concept of depth but does not really explain how to tell the texture to render behind everything else.[Edited by - nobodytold on April 14, 2010 6:32:37 PM]