游戏开发论坛

 找回密码
 立即注册
搜索
查看: 1562|回复: 1

在用DirectShow播放视频时怎样应用ALPHA混合?

[复制链接]

15

主题

31

帖子

35

积分

注册会员

Rank: 2

积分
35
发表于 2004-12-2 00:17:00 | 显示全部楼层 |阅读模式


主要是要实现让某种颜色变的透明。

我的视频播放的方法是使用DX9SDK中的Texture3D例子


HRESULT InitDShowTextureRenderer()
{
    HRESULT hr = S_OK;
    CComPtr<IBaseFilter>    pFSrc;          // Source Filter
    CComPtr<IPin>           pFSrcPinOut;    // Source Filter Output Pin   
    CTextureRenderer        *pCTR=0;        // DirectShow Texture renderer
   
    // Create the filter graph
    if (FAILED(g_pGB.CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC)))
       return E_FAIL;

#ifdef REGISTER_FILTERGRAPH
    // Register the graph in the Running Object Table (for debug purposes)
    AddToROT(g_pGB);
#endif
   
    // Create the Texture Renderer object
    pCTR = new CTextureRenderer(NULL, &hr);
    if (FAILED(hr) || !pCTR)
    {
        Msg(TEXT("Could not create texture renderer object!  hr=0x%x"), hr);
        return E_FAIL;
    }
   
    // Get a pointer to the IBaseFilter on the TextureRenderer, add it to graph
    g_pRenderer = pCTR;
    if (FAILED(hr = g_pGB->AddFilter(g_pRenderer, L"TEXTURERENDERER")))
    {
        Msg(TEXT("Could not add renderer filter to graph!  hr=0x%x"), hr);
        return hr;
    }
   
    // Determine the file to load based on DirectX Media path (from SDK)
    // Use a helper function included in DXUtils.cpp
    TCHAR strFileName[MAX_PATH];
    WCHAR wFileName[MAX_PATH];

    lstrcpyn( strFileName, DXUtil_GetDXSDKMediaPath(), MAX_PATH-1 );
    lstrcat( strFileName, SOURCE_FILE );
    strFileName[MAX_PATH-1] = 0;  // NULL-terminate
    wFileName[MAX_PATH-1] = 0;    // NULL-terminate

    USES_CONVERSION;
    wcsncpy(wFileName, T2W(strFileName), NUMELMS(wFileName));


       
    // Add the source filter to the graph.
    hr = g_pGB->AddSourceFilter (wFileName, L"SOURCE", &pFSrc);
   
    // If the media file was not found, inform the user.
    if (hr == VFW_E_NOT_FOUND)
    {
        Msg(TEXT("Could not add source filter to graph!  (hr==VFW_E_NOT_FOUND)\r\n\r\n")
            TEXT("This sample reads a media file from the DirectX SDK's media path.\r\n")
            TEXT(&quotlease install the DirectX 9 SDK on this machine."));
        return hr;
    }
    else if(FAILED(hr))
    {
        Msg(TEXT("Could not add source filter to graph!  hr=0x%x"), hr);
        return hr;
    }

    if (FAILED(hr = pFSrc->FindPin(L"Output", &pFSrcPinOut)))
    {
        Msg(TEXT("Could not find output pin!  hr=0x%x"), hr);
        return hr;
    }

#ifdef NO_AUDIO_RENDERER

    // If no audio component is desired, directly connect the two video pins
    // instead of allowing the Filter Graph Manager to render all pins.

    CComPtr<IPin> pFTRPinIn;      // Texture Renderer Input Pin

    // Find the source's output pin and the renderer's input pin
    if (FAILED(hr = pFTR->FindPin(L"In", &pFTRPinIn)))
    {
        Msg(TEXT("Could not find input pin!  hr=0x%x"), hr);
        return hr;
    }

    // Connect these two filters
    if (FAILED(hr = g_pGB->Connect(pFSrcPinOut, pFTRPinIn)))
    {
        Msg(TEXT("Could not connect pins!  hr=0x%x"), hr);
        return hr;
    }

#else

    // Render the source filter's output pin.  The Filter Graph Manager
    // will connect the video stream to the loaded CTextureRenderer
    // and will load and connect an audio renderer (if needed).



    if (FAILED(hr = g_pGB->Render(pFSrcPinOut)))
    {
        Msg(TEXT("Could not render source output pin!  hr=0x%x"), hr);
        return hr;
    }

#endif
   
    // Get the graph's media control, event & position interfaces
    g_pGB.QueryInterface(&g_pMC);
    g_pGB.QueryInterface(&g_pMP);
    g_pGB.QueryInterface(&g_pME);
   
    // Start the graph running;
    if (FAILED(hr = g_pMC->Run()))
    {
        Msg(TEXT("Could not run the DirectShow graph!  hr=0x%x"), hr);
        return hr;
    }

    return S_OK;
}

在对bmp平面图的处理中可以用颜色键屏蔽掉某种颜色





D3DXCreateTextureFromFileEx(pd3dDevice, "*.bmp", 0, 0, 0, 0,
                                                                                  D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT,
                                                                                  D3DX_DEFAULT, D3DCOLOR_XRGB(0, 0, 0), NULL, NULL, &m_pTexture);
       

但是在播放视频时好像不行?

请大家帮帮我,多谢!

15

主题

31

帖子

35

积分

注册会员

Rank: 2

积分
35
 楼主| 发表于 2004-12-3 13:25:00 | 显示全部楼层

Re:在用DirectShow播放视频时怎样应用ALPHA混合?




问题好像解决了,但我有点不明白。




    m_pd3dDevice->SetTexture( 0, g_pTexture );
    m_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof(CUSTOMVERTEX) );
    m_pd3dDevice->SetVertexShader( NULL );
    m_pd3dDevice->SetFVF( D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);

我加上了下面几句:

m_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE,   TRUE );           //打开ALPHA通道
m_pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCCOLOR );        //??
m_pd3dDevice->SetRenderState( D3DRS_DESTBLEND,D3DBLEND_INVSRCCOLOR );     //??

    m_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0,98);       //画纹理(mpg视频)

按照DX帮助文档中的介绍:

D3DBLEND_SRCCOLOR:  混合因子 (Rs,Gs,Bs,As)

D3DBLEND_INVSRCCOLOR:  混合因子 (1 - Rs, 1 - Gs, 1 - Bs, 1 - As)


但我不明白 Rs,Gs,Bs,As 分别是什么?如果是顶点的RGB值得话,那么他们是怎样赋值的?我的意思是,怎样得到的将黑色去掉的?如果我想把黑色换成蓝色该怎样做?


对于bmp格式的纹理来说,用下面的几句:

m_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE,   TRUE );  //打开ALPHA通道
m_pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ONE );   //D3DBLEND_ONE 混合(1, 1, 1,1)
m_pd3dDevice->SetRenderState( D3DRS_DESTBLEND,D3DBLEND_ONE );      

(1, 1, 1,1)代表黑色吗?
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-12-23 13:22

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表