玩玩DirectShow--(1)Sample: Texture3D9
位置Microsoft Platform SDK for Windows Server 2003 R2\Samples\Multimedia\DirectShow\Players\Texture3D9\
看名字就知道是把dshow解码出来的数据渲染到纹理上,但是这目录里面没有.proj项目文件,只有Makefile,为了方便,我们根据Makefile自己创建项目文件
附加包含目录: ..\..\BaseClasses;..\..\Common
链接
附加库目录: ..\..\BaseClasses\XP32_DEBUG
附加依赖项: d3dx9.lib d3d9.lib winmm.lib strmbasd.lib shell32.lib
这个strmbasd.lib不是安装了platform sdk就有了,要我们自己生成,如何生成呢?
选这个(Debug)的,进Samples目录,然后nmake,要比较长时间,出去遛个弯回来就好了
看到这样的画面应该就是生成好了。
使用多字节字符集 用unicode的话有函数链接的时候找不到【重剑注:因为链接的strmbasd.lib不是unicode的,看这个 玩玩DirectShow--(4)Platform SDK生成Unicode版本的strmbasd.lib 】
多线程调试(/MTd) 不用这个就一堆link2005的错误
截图:
核心源码:
hr
=
g_pd3dDevice
->
CreateTexture(uintWidth, uintHeight,
1
, D3DUSAGE_DYNAMIC,
D3DFMT_X8R8G8B8,D3DPOOL_DEFAULT,
& g_pTexture, NULL);
D3DFMT_X8R8G8B8,D3DPOOL_DEFAULT,
& g_pTexture, NULL);
Using Dynamic Textures
更新texture数据的部分
HRESULT CTextureRenderer::DoRenderSample( IMediaSample
*
pSample )
{
BYTE * pBmpBuffer, * pTxtBuffer; // Bitmap buffer, texture buffer
LONG lTxtPitch; // Pitch of bitmap, texture
BYTE * pbS = NULL;
DWORD * pdwS = NULL;
DWORD * pdwD = NULL;
UINT row, col, dwordWidth;
CheckPointer(pSample,E_POINTER);
CheckPointer(g_pTexture,E_UNEXPECTED);
// Get the video bitmap buffer
pSample -> GetPointer( & pBmpBuffer );
// Lock the Texture
D3DLOCKED_RECT d3dlr;
if ( m_bUseDynamicTextures )
{
if( FAILED(g_pTexture->LockRect(0, &d3dlr, 0 , D3DLOCK_DISCARD)))
return E_FAIL;
}
else
{
if (FAILED(g_pTexture -> LockRect( 0 , & d3dlr, 0 , 0 )))
return E_FAIL;
}
// Get the texture buffer & pitch
pTxtBuffer = static_cast<byte *> (d3dlr.pBits);
lTxtPitch = d3dlr.Pitch;
// Copy the bits
if (g_TextureFormat == D3DFMT_X8R8G8B8)
{
// Instead of copying data bytewise, we use DWORD alignment here.
// We also unroll loop by copying 4 pixels at once.
//
// original BYTE array is [b0][g0][r0][b1][g1][r1][b2][g2][r2][b3][g3][r3]
//
// aligned DWORD array is [b1 r0 g0 b0][g2 b2 r1 g1][r3 g3 b3 r2]
//
// We want to transform it to [ff r0 g0 b0][ff r1 g1 b1][ff r2 g2 b2][ff r3 b3 g3]
// below, bitwise operations do exactly this.
dwordWidth = m_lVidWidth / 4 ; // aligned width of the row, in DWORDS
// (pixel by 3 bytes over sizeof(DWORD))
for ( row = 0 ; row < (UINT)m_lVidHeight; row ++ )
{
pdwS = ( DWORD * )pBmpBuffer;
pdwD = ( DWORD * )pTxtBuffer;
for ( col = 0 ; col < dwordWidth; col ++ )
{
pdwD[ 0 ] = pdwS[ 0 ] | 0xFF000000 ;
pdwD[ 1 ] = ((pdwS[ 1 ] << 8 ) | 0xFF000000 ) | (pdwS[ 0 ] >> 24 );
pdwD[ 2 ] = ((pdwS[ 2 ] << 16 ) | 0xFF000000 ) | (pdwS[ 1 ] >> 16 );
pdwD[ 3 ] = 0xFF000000 | (pdwS[ 2 ] >> 8 );
pdwD += 4 ;
pdwS += 3 ;
}
// we might have remaining (misaligned) bytes here
pbS = (BYTE * ) pdwS;
for ( col = 0 ; col < (UINT)m_lVidWidth % 4 ; col ++ )
{
* pdwD = 0xFF000000 |
(pbS[ 2 ] << 16 ) |
(pbS[ 1 ] << 8 ) |
(pbS[ 0 ]);
pdwD ++ ;
pbS += 3 ;
}
pBmpBuffer += m_lVidPitch;
pTxtBuffer += lTxtPitch;
} // for rows
}
if (g_TextureFormat == D3DFMT_A1R5G5B5)
{
for ( int y = 0 ; y < m_lVidHeight; y ++ )
{
BYTE * pBmpBufferOld = pBmpBuffer;
BYTE * pTxtBufferOld = pTxtBuffer;
for ( int x = 0 ; x < m_lVidWidth; x ++ )
{
* (WORD * )pTxtBuffer = (WORD)
( 0x8000 +
((pBmpBuffer[ 2 ] & 0xF8 ) << 7 ) +
((pBmpBuffer[ 1 ] & 0xF8 ) << 2 ) +
(pBmpBuffer[ 0 ] >> 3 ));
pTxtBuffer += 2 ;
pBmpBuffer += 3 ;
}
pBmpBuffer = pBmpBufferOld + m_lVidPitch;
pTxtBuffer = pTxtBufferOld + lTxtPitch;
}
}
// Unlock the Texture
if (FAILED(g_pTexture->UnlockRect(0 )))
return E_FAIL;
return S_OK;
}
{
BYTE * pBmpBuffer, * pTxtBuffer; // Bitmap buffer, texture buffer
LONG lTxtPitch; // Pitch of bitmap, texture
BYTE * pbS = NULL;
DWORD * pdwS = NULL;
DWORD * pdwD = NULL;
UINT row, col, dwordWidth;
CheckPointer(pSample,E_POINTER);
CheckPointer(g_pTexture,E_UNEXPECTED);
// Get the video bitmap buffer
pSample -> GetPointer( & pBmpBuffer );
// Lock the Texture
D3DLOCKED_RECT d3dlr;
if ( m_bUseDynamicTextures )
{
if( FAILED(g_pTexture->LockRect(0, &d3dlr, 0 , D3DLOCK_DISCARD)))
return E_FAIL;
}
else
{
if (FAILED(g_pTexture -> LockRect( 0 , & d3dlr, 0 , 0 )))
return E_FAIL;
}
// Get the texture buffer & pitch
pTxtBuffer = static_cast<byte *> (d3dlr.pBits);
lTxtPitch = d3dlr.Pitch;
// Copy the bits
if (g_TextureFormat == D3DFMT_X8R8G8B8)
{
// Instead of copying data bytewise, we use DWORD alignment here.
// We also unroll loop by copying 4 pixels at once.
//
// original BYTE array is [b0][g0][r0][b1][g1][r1][b2][g2][r2][b3][g3][r3]
//
// aligned DWORD array is [b1 r0 g0 b0][g2 b2 r1 g1][r3 g3 b3 r2]
//
// We want to transform it to [ff r0 g0 b0][ff r1 g1 b1][ff r2 g2 b2][ff r3 b3 g3]
// below, bitwise operations do exactly this.
dwordWidth = m_lVidWidth / 4 ; // aligned width of the row, in DWORDS
// (pixel by 3 bytes over sizeof(DWORD))
for ( row = 0 ; row < (UINT)m_lVidHeight; row ++ )
{
pdwS = ( DWORD * )pBmpBuffer;
pdwD = ( DWORD * )pTxtBuffer;
for ( col = 0 ; col < dwordWidth; col ++ )
{
pdwD[ 0 ] = pdwS[ 0 ] | 0xFF000000 ;
pdwD[ 1 ] = ((pdwS[ 1 ] << 8 ) | 0xFF000000 ) | (pdwS[ 0 ] >> 24 );
pdwD[ 2 ] = ((pdwS[ 2 ] << 16 ) | 0xFF000000 ) | (pdwS[ 1 ] >> 16 );
pdwD[ 3 ] = 0xFF000000 | (pdwS[ 2 ] >> 8 );
pdwD += 4 ;
pdwS += 3 ;
}
// we might have remaining (misaligned) bytes here
pbS = (BYTE * ) pdwS;
for ( col = 0 ; col < (UINT)m_lVidWidth % 4 ; col ++ )
{
* pdwD = 0xFF000000 |
(pbS[ 2 ] << 16 ) |
(pbS[ 1 ] << 8 ) |
(pbS[ 0 ]);
pdwD ++ ;
pbS += 3 ;
}
pBmpBuffer += m_lVidPitch;
pTxtBuffer += lTxtPitch;
} // for rows
}
if (g_TextureFormat == D3DFMT_A1R5G5B5)
{
for ( int y = 0 ; y < m_lVidHeight; y ++ )
{
BYTE * pBmpBufferOld = pBmpBuffer;
BYTE * pTxtBufferOld = pTxtBuffer;
for ( int x = 0 ; x < m_lVidWidth; x ++ )
{
* (WORD * )pTxtBuffer = (WORD)
( 0x8000 +
((pBmpBuffer[ 2 ] & 0xF8 ) << 7 ) +
((pBmpBuffer[ 1 ] & 0xF8 ) << 2 ) +
(pBmpBuffer[ 0 ] >> 3 ));
pTxtBuffer += 2 ;
pBmpBuffer += 3 ;
}
pBmpBuffer = pBmpBufferOld + m_lVidPitch;
pTxtBuffer = pTxtBufferOld + lTxtPitch;
}
}
// Unlock the Texture
if (FAILED(g_pTexture->UnlockRect(0 )))
return E_FAIL;
return S_OK;
}
2009-1-9 这个例子用到了platform sdk中的BaseClasses,用到引擎中的时候麻烦多多,我搞了几天,愣是编译不过!我日!考虑放弃dshow,用xvid
在游戏中播放过场电影