IDirect3DSurface9* dxManager::getSurfaceFromBitmap(std::string filename)
{
HRESULT hResult;
IDirect3DSurface9* surface = NULL;
D3DXIMAGE_INFO imageInfo;
// Get the width and height info from this bitmap
hResult = D3DXGetImageInfoFromFile(filename.c_str(), &imageInfo);
if FAILED (hResult)
return NULL;
hResult = pd3dDevice>CreateOffscreenPlainSurface(imageInfo.Width,
imageInfo.Height, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT,
&surface, NULL);
if (FAILED(hResult))
return NULL;
hResult = D3DXLoadSurfaceFromFile(surface, NULL, NULL,
filename.c_str(), NULL, D3DX_DEFAULT,
D3DCOLOR_ARGB(0xff,0,0,0), NULL);
if (FAILED(hResult))
return NULL;
return surface;
}
// turn on alpha blending
pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true );
pd3dDevice->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_SRCCOLOR);
pd3dDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCCOLOR);
// blit (using separate getBackBuffer function for the back buffer)
pd3dDevice->StretchRect(srcSurface, srcRect, getBackBuffer(),
destRect, D3DTEXF_NONE);
// present the backbuffer contents to the display
pd3dDevice->Present( NULL, NULL, NULL, NULL );