tags:

views:

81

answers:

1

I need to render a simple texture mapped model as the output of a directshow source filter. The 3d rendering doesnt need to come from Direct3D, but that would be nice. OpenGL or any other provider would be fine assuming I can fit it into the context of the DirectShow source filter.

visual studio 2008 c++

A: 

With direct3d I have found that you can call GetRenderTargetData from the d3d device to get you access to the raw image bytes that you can then copy into the source filters image buffer

Here is example code of how to get the d3d render

void CaptureRenderTarget(IDirect3DDevice9* pdev)
{
    IDirect3DSurface9* pTargetSurface=NULL;
    HRESULT hr=pdev->GetRenderTarget(0,&pTargetSurface);
    if(SUCCEEDED(hr))
    {
        D3DSURFACE_DESC desc;
        hr=pTargetSurface->GetDesc(&desc);
        if(SUCCEEDED(hr))
        {
            IDirect3DTexture9* pTempTexture=NULL;
            hr=pdev->CreateTexture(desc.Width,desc.Height,1,0,desc.Format,D3DPOOL_SYSTEMMEM,&pTempTexture,NULL);
            if(SUCCEEDED(hr))
            {
                IDirect3DSurface9* pTempSurface=NULL;
                hr=pTempTexture->GetSurfaceLevel(0,&pTempSurface);
                if(SUCCEEDED(hr))
                {
                    hr=pdev->GetRenderTargetData(pTargetSurface,pTempSurface);
                    if(SUCCEEDED(hr))
                    {
                        //D3DXSaveTextureToFile(L"Output.png",D3DXIFF_PNG,pTempTexture,NULL);
                        D3DLOCKED_RECT data;
                        hr=pTempTexture->LockRect(0, &data, NULL, 0);
                        if(SUCCEEDED(hr))
                        {
                            BYTE *d3dPixels = (BYTE*)data.pBits;                                            
                        }
                        pTempTexture->UnlockRect(0);
                    }
                    pTempSurface->Release();
                }
                pTempTexture->Release();
            }
        }
        pTargetSurface->Release();
    }
}
Mr Bell