本文整理汇总了C++中LPDIRECT3DTEXTURE9::LockRect方法的典型用法代码示例。如果您正苦于以下问题:C++ LPDIRECT3DTEXTURE9::LockRect方法的具体用法?C++ LPDIRECT3DTEXTURE9::LockRect怎么用?C++ LPDIRECT3DTEXTURE9::LockRect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LPDIRECT3DTEXTURE9
的用法示例。
在下文中一共展示了LPDIRECT3DTEXTURE9::LockRect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: blit
void DevState::blit(unsigned int x, unsigned int y, unsigned int w, unsigned int h) {
// Blit is called often. Thus, we do not want to always log here.
#ifdef EXTENDED_OVERLAY_DEBUGOUTPUT
ods("D3D9: Blit %d %d %d %d", x, y, w, h);
#endif
if (! texTexture || !a_ucTexture)
return;
D3DLOCKED_RECT lr;
if ((x == 0) && (y == 0) && (w == uiWidth) && (h == uiHeight)) {
if (texTexture->LockRect(0, &lr, NULL, D3DLOCK_DISCARD) != D3D_OK)
return;
} else {
RECT r;
r.left = x;
r.top = y;
r.right = x + w;
r.bottom = y + h;
if (texTexture->LockRect(0, &lr, &r, 0) != D3D_OK)
return;
}
for (unsigned int r=0;r < h;++r) {
unsigned char *dptr = reinterpret_cast<unsigned char *>(lr.pBits) + r * lr.Pitch;
unsigned char *sptr = a_ucTexture + 4 * ((y + r) * uiWidth + x);
memcpy(dptr, sptr, w * 4);
}
texTexture->UnlockRect(0);
}
示例2: blit
void DevState::blit(unsigned int x, unsigned int y, unsigned int w, unsigned int h) {
ods("D3D9: Blit %d %d %d %d", x, y, w, h);
if (! texTexture || !a_ucTexture)
return;
D3DLOCKED_RECT lr;
if ((x == 0) && (y == 0) && (w == uiWidth) && (h == uiHeight)) {
if (texTexture->LockRect(0, &lr, NULL, D3DLOCK_DISCARD) != D3D_OK)
return;
} else {
RECT r;
r.left = x;
r.top = y;
r.right = x + w;
r.bottom = y + h;
if (texTexture->LockRect(0, &lr, &r, 0) != D3D_OK)
return;
}
for (unsigned int r=0;r < h;++r) {
unsigned char *dptr = reinterpret_cast<unsigned char *>(lr.pBits) + r * lr.Pitch;
unsigned char *sptr = a_ucTexture + 4 * ((y + r) * uiWidth + x);
memcpy(dptr, sptr, w * 4);
}
texTexture->UnlockRect(0);
}
示例3:
IDirect3DTexture9 *CreatTex(LPSTR dat)
{
LPDIRECT3DTEXTURE9 pTex = NULL;
UINT xx,yy;
xx = *(UINT*)(dat+4);
yy = *(UINT*)(dat+8);
D3DLOCKED_RECT rc;
HRESULT hr;
if (*(DWORD*)(dat+0x28) == 'DXT3')
{
hr = g_pD3DDevice->CreateTexture(xx,yy,0,0 ,D3DFMT_DXT3,D3DPOOL_MANAGED,&pTex,NULL);
if (hr != D3D_OK) return NULL;
hr = pTex->LockRect(0,&rc,NULL,0);
if (hr == D3D_OK)
{
CopyMemory(rc.pBits,dat+0x28+12,(xx/4) * (yy/4) * 16 );
pTex->UnlockRect(0);
}
return pTex;
}
if (*(DWORD*)(dat+0x28) == 'DXT1')
{
hr = g_pD3DDevice->CreateTexture(xx,yy,0,0,D3DFMT_DXT1,D3DPOOL_MANAGED,&pTex,NULL);
if (hr != D3D_OK) return NULL;
hr = pTex->LockRect(0,&rc,NULL,0);
if (hr == D3D_OK)
{
CopyMemory(rc.pBits,dat+0x28+12,(xx/4) * (yy/4) * 8 );
pTex->UnlockRect(0);
}
return pTex;
}
hr = g_pD3DDevice->CreateTexture(xx,yy,0,0,D3DFMT_A8R8G8B8,D3DPOOL_MANAGED,&pTex,NULL);
if (hr != D3D_OK) return NULL;
hr = pTex->LockRect(0,&rc,NULL,0);
if (hr == D3D_OK)
{
for (DWORD jy = 0; jy < yy; ++jy)
{
for (DWORD jx = 0; jx < xx; ++jx)
{
DWORD *pp = (DWORD *)rc.pBits;
BYTE *idx = (BYTE *)(dat+0x28+0x400);
DWORD *pal = (DWORD *)(dat+0x28);
pp[(yy-jy-1)*xx+jx] = pal[idx[jy*xx+jx]];
}
}
pTex->UnlockRect(0);
}
return pTex;
}
示例4: l_Image_Load
int l_Image_Load( lua_State* L )
{
D3DXIMAGE_INFO imgInfo;
const char* fileName = lua_tostring( L, 1 );
bool dxtCompression = false;
D3DFORMAT d3dfmt = D3DFMT_UNKNOWN;
//check for dds format
{
if( _strcmpi( "dds", fileName + strlen( fileName ) - 3 ) == 0 )
{
DDSHEAD header;
FILE* f;
if(fopen_s( &f, fileName, "rb" ) == 0)
{
if( fread( &header, sizeof(header), 1, f ) == 1 )
{
if( strncmp( (const char*)header.Signature, "DDS ", 4 ) == 0 && ( header.FourCC == D3DFMT_DXT1 || header.FourCC == D3DFMT_DXT3 || header.FourCC == D3DFMT_DXT5 ) )
{
d3dfmt = D3DFMT_A8R8G8B8;
}
}
fclose(f);
}
}
}
LPDIRECT3DTEXTURE9 texture;
HRESULT hr = D3DXCreateTextureFromFileEx( g_pd3dDevice, fileName, D3DX_DEFAULT_NONPOW2, D3DX_DEFAULT_NONPOW2, D3DX_FROM_FILE, 0, d3dfmt, D3DPOOL_SCRATCH, D3DX_DEFAULT, D3DX_DEFAULT, 0, &imgInfo, 0, &texture );
if( FAILED( hr ) )
{
return 0;
}
ImageData* imgData = createImage();
imgData->width = imgInfo.Width;
imgData->height = imgInfo.Height;
imgData->format = getFormatByD3D( imgInfo.Format );
imgData->imgData = malloc( imgData->width * imgData->height * imgData->format->bytesPerPixel );
D3DLOCKED_RECT rect;
texture->LockRect(0, &rect, 0, 0 );
memcpy( imgData->imgData, rect.pBits, imgData->width * imgData->height * imgData->format->bytesPerPixel );
texture->UnlockRect( 0 );
texture->Release();
//lua_pushlightuserdata( L, imgData );
ImageData** luaData = lua_pushimage( L );
*luaData = imgData;
return 1;
}
示例5:
LPDIRECT3DTEXTURE9 D3D9::CreateTexture(int texWidth, int texHeight, D3DCOLOR color)
{
LPDIRECT3DTEXTURE9 pTexture;
HRESULT hr = D3DXCreateTexture(d3ddevice_,
texWidth,
texHeight,
0,
0,
D3DFMT_A8R8G8B8, // 4 bytes for a pixel
D3DPOOL_MANAGED,
&pTexture);
if (FAILED(hr))
{
MessageBox(NULL, L"Create texture failed", L"Error", 0);
}
// Lock the texture and fill in color
D3DLOCKED_RECT lockedRect;
hr = pTexture->LockRect(0, &lockedRect, NULL, 0);
if (FAILED(hr))
{
MessageBox(NULL, L"Lock texture failed!", L"Error", 0);
}
DWORD sideColor = 0xff000000; // the side line color
int side_width = 10;
// Calculate number of rows in the locked Rect
int rowCount = (texWidth * texHeight * 4 ) / lockedRect.Pitch;
for (int i = 0; i < texWidth; ++i)
{
for (int j = 0; j < texHeight; ++j)
{
int index = i * rowCount + j;
int* pData = (int*)lockedRect.pBits;
if (i <= side_width || i >= texWidth - side_width
|| j <= side_width || j >= texHeight - side_width)
{
memcpy(&pData[index], &sideColor, 4);
}
else
{
memcpy(&pData[index], &color, 4);
}
}
}
pTexture->UnlockRect(0);
return pTexture;
}
示例6: DrawScene
// シーンの描画
void DrawScene(void* data)
{
#if 1
struct vertex
{
FLOAT x, y, z, rhw;
FLOAT tu, tv;
};
vertex v[4] =
{
{0, 0, 0.0f, 1.0f, 0.0f, 0.0f},
{SCREEN_WIDTH, 0, 0.0f, 1.0f, 1.0f, 0.0f},
{0, SCREEN_HEIGHT, 0.0f, 1.0f, 0.0f, 1.0f},
{SCREEN_WIDTH, SCREEN_HEIGHT, 0.0f, 1.0f, 1.0f, 1.0f},
};
D3DLOCKED_RECT pRect;
DWORD time,lasttime;
lasttime = timeGetTime();
time = lasttime;
while(true)
{
time = timeGetTime();
if(time-lasttime >= 1000*10)
{
g_tex->LockRect(0, &pRect, NULL, D3DLOCK_DISCARD);
for(int y = 0; y<SCREEN_HEIGHT; y++)
{
for(int x = 0; x<SCREEN_WIDTH; x++)
{
DWORD color = 0x00ff00ff;
color = (edupt::to_int(image[y*SCREEN_WIDTH+x].x_)<<16) + (edupt::to_int(image[y*SCREEN_WIDTH+x].y_)<<8) + edupt::to_int(image[y*SCREEN_WIDTH+x].z_);
memcpy((BYTE*)pRect.pBits+pRect.Pitch*y + 4*x, &color, sizeof(DWORD));
}
}
g_tex->UnlockRect(0);
lasttime = time;
}
g_pD3DDev->BeginScene();
g_pD3DDev->Clear(0,NULL,D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,D3DCOLOR_RGBA(128,128,128,0),1.0f,0);
g_pD3DDev->SetFVF(D3DFVF_XYZRHW | D3DFVF_TEX1);
g_pD3DDev->SetTexture(0, g_tex);
g_pD3DDev->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, v, sizeof(vertex));
g_pD3DDev->EndScene();
g_pD3DDev->Present(NULL, NULL, NULL, NULL);
}
#endif
}
示例7: copy_texture_bits
static void copy_texture_bits( LPTEXTURE srcT, LPTEXTURE dstT )
{
HRESULT hr;
D3DLOCKED_RECT srcRect;
D3DLOCKED_RECT dstRect;
unsigned int y, x;
BYTE* srcBits;
BYTE* dstBits;
D3DSURFACE_DESC srcDesc;
LPDIRECT3DTEXTURE9 srcTexture = (LPDIRECT3DTEXTURE9) srcT;
LPDIRECT3DTEXTURE9 dstTexture = (LPDIRECT3DTEXTURE9) dstT;
srcTexture->GetLevelDesc(0,&srcDesc);
hr = srcTexture->LockRect(0,&srcRect,NULL,D3DLOCK_READONLY);
if(FAILED(hr))
return;
hr = dstTexture->LockRect(0,&dstRect,NULL,D3DLOCK_DISCARD);
if(FAILED(hr))
return;
srcBits = (BYTE*)srcRect.pBits;
dstBits = (BYTE*)dstRect.pBits;
for (y = 0; y < srcDesc.Height; y++)
{
for (x = 0; x < srcDesc.Width; x++)
{
// move to the correct off set in the table
// pitch is the width of a row
// (x*size) is the length of each pixel data
DWORD srcIndex = (x*4)+(y*srcRect.Pitch);
DWORD dstIndex = (x*4)+(y*dstRect.Pitch);
// D3DFMT_A8R8G8B8 data will be accessible backwards: bgra
dstBits[dstIndex] = (BYTE)gamma_table[srcBits[srcIndex]]; // Blue
dstBits[dstIndex+1] = (BYTE)gamma_table[srcBits[srcIndex+1]]; // Green
dstBits[dstIndex+2] = (BYTE)gamma_table[srcBits[srcIndex+2]]; // Red
dstBits[dstIndex+3] = (BYTE)gamma_table[srcBits[srcIndex+3]]; // Alpha
}
}
dstTexture->UnlockRect(0);
srcTexture->UnlockRect(0);
}
示例8: createTexure_
bool Atlas::createTexure_( Logger & _logger, const MAGIC_CHANGE_ATLAS & c, LPDIRECT3DTEXTURE9 * _texture )
{
uint32_t image_width;
uint32_t image_height;
unsigned char * pixels = nullptr;
if( c.data == nullptr )
{
pixels = imageLoadFromFile( c.file, image_width, image_height );
}
else
{
pixels = imageLoadFromMemory( c.data, c.length, image_width, image_height );
}
unsigned char * correct_pixels = pixels;
UINT texture_width = getTexturePOW2( image_width );
UINT texture_height = getTexturePOW2( image_height );
LPDIRECT3DTEXTURE9 texture = NULL;
if( m_pDevice->CreateTexture( texture_width, texture_height, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &texture, NULL ) != D3D_OK )
{
return false;
}
D3DLOCKED_RECT lockedRect;
DXCALL texture->LockRect( 0, &lockedRect, NULL, D3DLOCK_DISCARD );
if( lockedRect.pBits == NULL || lockedRect.Pitch == 0 )
{
return false;
}
for( size_t i = 0; i != image_height; ++i )
{
unsigned char * image = correct_pixels + i * image_width * 4;
unsigned char * bits = static_cast<unsigned char *>(lockedRect.pBits) + lockedRect.Pitch * i;
std::copy( image, image + image_width * 4, bits );
}
DXCALL texture->UnlockRect( 0 );
imageFree( pixels );
*_texture = texture;
return true;
}
示例9: init
bool AlphaMap::init(bool pAlphaCheck, LPDIRECT3DTEXTURE9 pTexture)
{
d_solid = true;
if (!pAlphaCheck)
return false;
D3DSURFACE_DESC surfaceDesc;
pTexture->GetLevelDesc(0, &surfaceDesc);
d_width = surfaceDesc.Width;
d_height = surfaceDesc.Height;
d_mask.resize(d_width * d_height);
D3DLOCKED_RECT lockedRect;
if (SUCCEEDED(pTexture->LockRect(0, &lockedRect, NULL, D3DLOCK_DISCARD)))
{
unsigned char* bits = (unsigned char*)lockedRect.pBits;
for (int y = 0; y < d_height; ++y)
{
for (int x = 0; x < d_width; ++x)
{
bool solid = (bits[x * 4 + y * lockedRect.Pitch + 3] != 0);
d_mask[x + y * d_width] = solid;
if (!solid)
d_solid = false;
}
}
pTexture->UnlockRect(0);
}
return true;
}
示例10: return
lpta::LptaTexture::DATA LptaD3DTextureManager::GenerateDefaultData(void)
{
LPDIRECT3DTEXTURE9 textureData = nullptr;
D3DLOCKED_RECT d3dLockedRect;
HRESULT result = d3ddev->CreateTexture(
DEFAULT_TEXTURE_WIDTH, DEFAULT_TEXTURE_HEIGHT,
1, 0,
D3DFMT_A8R8G8B8,
D3DPOOL_MANAGED,
&textureData,
nullptr
);
if (FAILED(result)) {
throw TextureD3DFailure("could not obtain texture object for default");
}
result = textureData->LockRect(0, &d3dLockedRect, nullptr, 0);
if (FAILED(result)) {
textureData->Release();
throw TextureD3DFailure("failed to lock rectangle to set default texture color");
}
unsigned long *rawData = (unsigned long *)d3dLockedRect.pBits;
for (unsigned long *pixel = rawData;
pixel < rawData + (DEFAULT_TEXTURE_WIDTH * DEFAULT_TEXTURE_HEIGHT); ++pixel) {
*pixel = DEFAULT_TEXTURE_COLOR;
}
textureData->UnlockRect(0);
return (lpta::LptaTexture::DATA)textureData;
}
示例11:
/* Copy bitmap->memory to texture memory */
static void d3d_sync_bitmap_texture(ALLEGRO_BITMAP *bitmap,
int x, int y, int width, int height)
{
D3DLOCKED_RECT locked_rect;
RECT rect;
ALLEGRO_BITMAP_D3D *d3d_bmp = (ALLEGRO_BITMAP_D3D *)bitmap;
LPDIRECT3DTEXTURE9 texture;
rect.left = x;
rect.top = y;
rect.right = x + width;
rect.bottom = y + height;
if (_al_d3d_render_to_texture_supported())
texture = d3d_bmp->system_texture;
else
texture = d3d_bmp->video_texture;
if (texture->LockRect(0, &locked_rect, &rect, 0) == D3D_OK) {
_al_convert_bitmap_data(bitmap->memory, bitmap->format, bitmap->w*al_get_pixel_size(bitmap->format),
locked_rect.pBits, bitmap->format, locked_rect.Pitch,
x, y, 0, 0, width, height);
/* Copy an extra row and column so the texture ends nicely */
if (rect.bottom > bitmap->h) {
_al_convert_bitmap_data(
bitmap->memory,
bitmap->format, bitmap->w*al_get_pixel_size(bitmap->format),
locked_rect.pBits,
bitmap->format, locked_rect.Pitch,
0, bitmap->h-1,
0, height,
width, 1);
}
if (rect.right > bitmap->w) {
_al_convert_bitmap_data(
bitmap->memory,
bitmap->format, bitmap->w*al_get_pixel_size(bitmap->format),
locked_rect.pBits,
bitmap->format, locked_rect.Pitch,
bitmap->w-1, 0,
width, 0,
1, height);
}
if (rect.bottom > bitmap->h && rect.right > bitmap->w) {
_al_convert_bitmap_data(
bitmap->memory,
bitmap->format, bitmap->w*al_get_pixel_size(bitmap->format),
locked_rect.pBits,
bitmap->format, locked_rect.Pitch,
bitmap->w-1, bitmap->h-1,
width, height,
1, 1);
}
texture->UnlockRect(0);
}
else {
ALLEGRO_ERROR("d3d_sync_bitmap_texture: Couldn't lock texture to upload.\n");
}
}
示例12: InitVB
/**-----------------------------------------------------------------------------
* 정점버퍼를 생성하고 정점값을 채워넣는다.
* HeightMap정보도 여기서 초기화한다.
*------------------------------------------------------------------------------
*/
HRESULT InitVB()
{
D3DSURFACE_DESC ddsd;
D3DLOCKED_RECT d3drc;
g_pTexHeight->GetLevelDesc( 0, &ddsd ); // 텍스처의 정보
g_cxHeight = ddsd.Width; // 텍스처의 가로크기
g_czHeight = ddsd.Height; // 텍스처의 세로크기
g_pLog->Log( "Texture Size:[%d,%d]", g_cxHeight, g_czHeight );
g_pvHeightMap = new D3DXVECTOR3[g_cxHeight * g_czHeight]; // 높이맵배열 생성
if ( FAILED( g_pd3dDevice->CreateVertexBuffer( ddsd.Width*ddsd.Height*sizeof( CUSTOMVERTEX ),
0, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &g_pVB, NULL ) ) )
{
return E_FAIL;
}
// 텍스처 메모리 락!
g_pTexHeight->LockRect( 0, &d3drc, NULL, D3DLOCK_READONLY );
VOID* pVertices;
// 정점버퍼 락!
if ( FAILED( g_pVB->Lock( 0, g_cxHeight*g_czHeight*sizeof( CUSTOMVERTEX ), (void**)&pVertices, 0 ) ) )
{
return E_FAIL;
}
CUSTOMVERTEX v;
CUSTOMVERTEX* pV = (CUSTOMVERTEX*)pVertices;
for ( DWORD z = 0; z < g_czHeight; z++ )
{
for ( DWORD x = 0; x < g_cxHeight; x++ )
{
v.p.x = (float)x - g_cxHeight / 2.0f; // 정점의 x좌표(메시를 원점에 정렬)
v.p.z = -( (float)z - g_czHeight / 2.0f ); // 정점의 z좌표(메시를 원점에 정렬), z축이 모니터안쪽이므로 -를 곱한다.
v.p.y = ( (float)( *( (LPDWORD)d3drc.pBits + x + z*( d3drc.Pitch / 4 ) ) & 0x000000ff ) ) / 10.0f; /// DWORD이므로 pitch/4
v.n.x = v.p.x;
v.n.y = v.p.y;
v.n.z = v.p.z;
D3DXVec3Normalize( &v.n, &v.n );
v.t.x = (float)x / ( g_cxHeight - 1 );
v.t.y = (float)z / ( g_czHeight - 1 );
*pV++ = v; // 정점버퍼에 정점 저장
g_pvHeightMap[z * g_cxHeight + x] = v.p; // 높이맵에 정점 저장
}
}
g_pVB->Unlock();
g_pTexHeight->UnlockRect( 0 );
return S_OK;
}
示例13: switch
void AmjuGLDX9::SetTexture(
AmjuGL::TextureHandle* th,
AmjuGL::TextureType tt,
AmjuGL::TextureDepth td,
int width,
int height,
uint8* data)
{
AMJU_CALL_STACK;
HRESULT res = D3DXCreateTexture(
dd, //LPDIRECT3DDEVICE9 pDevice,
width, //UINT Width,
height, //UINT Height,
0, // Mip Levels: 0 means create all
D3DUSAGE_DYNAMIC, //DWORD Usage,
(td == AmjuGL::AMJU_RGB ? D3DFMT_R8G8B8 : D3DFMT_A8R8G8B8), //D3DFORMAT Format,
D3DPOOL_DEFAULT, // Pool,
reinterpret_cast<LPDIRECT3DTEXTURE9*>(th) //LPDIRECT3DTEXTURE9 * ppTexture
);
LPDIRECT3DTEXTURE9 pTex = reinterpret_cast<LPDIRECT3DTEXTURE9>(*th);
D3DLOCKED_RECT lockedRect;
pTex->LockRect(0, &lockedRect, NULL, 0);
switch (td)
{
case AmjuGL::AMJU_RGB:
CopyRGBTexture((uint8*)lockedRect.pBits, lockedRect.Pitch, data, width, height);
break;
case AmjuGL::AMJU_RGBA:
CopyRGBATexture((uint8*)lockedRect.pBits, lockedRect.Pitch, data, width, height);
break;
}
pTex->UnlockRect(0);
// TODO Create data for each mipmap level.
// NB We want the same functionality as screenshot shrinking.
IDirect3DSurface9 * pSurfaceLevel;
for (unsigned int iLevel = 0; iLevel < pTex->GetLevelCount(); iLevel++)
{
pTex->GetSurfaceLevel(iLevel, &pSurfaceLevel);
// TODO Write this mip map
pSurfaceLevel->Release();
}
}
示例14: texture
/* CDirect3D::BlankTexture
clears a texture (fills it with zeroes)
IN:
texture - the texture to be blanked
-----
returns true if successful, false otherwise
*/
bool CDirect3D::BlankTexture(LPDIRECT3DTEXTURE9 texture)
{
D3DLOCKED_RECT lr;
HRESULT hr;
if(FAILED(hr = texture->LockRect(0, &lr, NULL, 0))) {
DXTRACE_ERR_MSGBOX(TEXT("Unable to lock texture"), hr);
return false;
} else {
memset(lr.pBits, 0, lr.Pitch * quadTextureSize);
texture->UnlockRect(0);
return true;
}
}
示例15: SetColorKey
bool CAnimationSpooler::SetColorKey(LPDIRECT3DTEXTURE9 pTexture, LPDIRECT3DSURFACE9 pSurface, int iTexSize, COLORREF clrColorKey)
{
ASSERT(pTexture);
ASSERT(pSurface);
if( clrColorKey == CLR_INVALID ) return true;
// Get colorkey's red, green, and blue components
// and put the colorkey in the texture's native format
DWORD r = GetRValue(clrColorKey);
DWORD g = GetGValue(clrColorKey);
DWORD b = GetBValue(clrColorKey);
DWORD dwColorKey = D3DCOLOR_ARGB(255,r,g,b);
HRESULT Hr;
LPDIRECT3DTEXTURE9 pTex = NULL;
Hr = m_p3DDevice->CreateTexture(iTexSize, iTexSize, 1, D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &pTex, NULL);
if( FAILED(Hr) ) return false;
CSafeRelease<IDirect3DTexture9> RefTex = pTex;
LPDIRECT3DSURFACE9 pTexSurf = NULL;
Hr = pTex->GetSurfaceLevel(0, &pTexSurf);
if( FAILED(Hr) ) return false;
CSafeRelease<IDirect3DSurface9> RefTexSurf = pTexSurf;
Hr = m_p3DDevice->GetRenderTargetData(pSurface, pTexSurf);
if( FAILED(Hr) ) return false;
// Lock the texture and scan through each pixel, replacing the colorkey pixels
D3DLOCKED_RECT d3dlr;
Hr = pTex->LockRect(0, &d3dlr, 0, 0);
if( FAILED(Hr) ) return false;
DWORD* pBits = static_cast<DWORD*>(d3dlr.pBits);
for( int y = 0; y < iTexSize; y++ ) {
for( int x = 0; x < iTexSize; x++ ) {
if( pBits[x] == dwColorKey ) pBits[x] = 0x00000000;
else pBits[x] |= 0xff000000;
}
pBits += d3dlr.Pitch / sizeof(DWORD);
}
pTex->UnlockRect(0);
// Copy modified data back
POINT pt = { 0, 0 };
RECT rcDest = { 0, 0, iTexSize, iTexSize };
Hr = m_p3DDevice->UpdateSurface(pTexSurf, &rcDest, pSurface, &pt);
return true;
}