|
|
以下代码是模拟OPENGL里的glReadPixels函数,就是得到图像内容buffer,我需要对图像进行处理。
有些问题:
为什么要CreateRenderTarget设置一个新的渲染目标?
如果使用 IDirect3DDevice9::GetBackBuffer呢? 有什么差别吗?
int mySetRenderTarget( IDirect3DSurface9 **surf, int width, int height, D3DFORMAT fmt )
{
HRESULT hr;
IDirect3DSurface9 *s = 0;
hr = g_pd3dDevice->CreateRenderTarget( width, height, fmt, D3DMULTISAMPLE_NONE, 0, TRUE, &s, 0 );
if( FAILED( hr ) )
return 0;
*surf = s;
hr = g_pd3dDevice->SetRenderTarget( 0, s );
if( FAILED( hr ) )
return 0;
return 1;
}
int myReadPixel( IDirect3DSurface9 *surf, int x, int y, mycolor *data )
{
D3DLOCKED_RECT lr;
HRESULT hr = surf->LockRect( &lr, 0, D3DLOCK_READONLY );
if( FAILED( hr ) )
return 0;
mycolor *cbuf = ((mycolor*)lr.pBits) + x * 4 + y * lr.Pitch;
if( !cbuf )
return 0;
data->alpha = cbuf->alpha;
data->red = cbuf->red;
data->green = cbuf->green;
data->blue = cbuf->blue;
surf->UnlockRect();
}
|
|