?? dxmanager.cpp
字號:
#include ".\dxmanager.h"
dxManager::dxManager(void)
{
pD3D = NULL;
pd3dDevice = NULL;
}
dxManager::~dxManager(void)
{
}
bool dxManager::init(HWND hwnd)
{
if( NULL == ( pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
{
lastResult = E_FAIL;
return false;
}
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory( &d3dpp, sizeof(d3dpp) );
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
d3dpp.BackBufferCount = 1;
d3dpp.BackBufferHeight = 480;
d3dpp.BackBufferWidth = 640;
d3dpp.hDeviceWindow = hwnd;
if( FAILED( pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &pd3dDevice ) ) )
{
lastResult = E_FAIL;
return false;
}
return true;
}
void dxManager::shutdown(void)
{
if( pd3dDevice != NULL)
{
pd3dDevice->Release();
pd3dDevice = NULL;
}
if( pD3D != NULL)
{
pD3D->Release();
pD3D = NULL;
}
}
void dxManager::beginRender()
{
if( NULL == pd3dDevice )
return;
// Clear the backbuffer to a blue color
pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(255,255,255), 1.0f, 0 );
}
void dxManager::endRender(void)
{
// Present the backbuffer contents to the display
pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
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_X8R8G8B8, D3DPOOL_DEFAULT, &surface, NULL);
if (FAILED(hResult))
return NULL;
hResult = D3DXLoadSurfaceFromFile(surface, NULL, NULL, filename.c_str(), NULL, D3DX_DEFAULT, 0, NULL);
if (FAILED(hResult))
return NULL;
return surface;
}
IDirect3DSurface9* dxManager::getBackBuffer(void)
{
IDirect3DSurface9* backbuffer = NULL;
if (!pd3dDevice)
return NULL;
HRESULT hResult = pd3dDevice->GetBackBuffer(0,0,D3DBACKBUFFER_TYPE_MONO, &backbuffer);
if (FAILED(hResult))
return NULL;
else
return backbuffer;
}
void dxManager::blitToSurface(IDirect3DSurface9* srcSurface, const RECT *srcRect, const RECT *destRect)
{
pd3dDevice->StretchRect(srcSurface, srcRect, getBackBuffer(), destRect, D3DTEXF_NONE);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -