开发者

How can I render 3d graphics in a directshow source filter

开发者 https://www.devze.com 2023-01-02 06:16 出处:网络
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 oth

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++


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();
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消