|
|
#include <d3d8.h>
#pragma comment(lib,"d3d8.lib")
LPDIRECT3D8 pD3D = NULL;
LPDIRECT3DDEVICE8 pD3DDevice = NULL;
HRESULT Init3D(HWND hWnd)
{
pD3D = Direct3DCreate8(D3D_SDK_VERSION);
if(pD3D == NULL)
{
return E_FAIL;
}
D3DDISPLAYMODE d3ddm;
if(FAILED(pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT,&d3ddm)
{
return E_FAIL;
}
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp,sizeof(d3dpp));
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC;
d3dpp.BackBufferFormat = d3ddm.Format;
if(FAILED(pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_pD3DDevice)))
{
return E_FAIL;
}
return S_OK;
}
void Render()
{
if(pD3DDevice == NULL)
{
return;
}
pD3DDevice->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(60,60,60),1.0f,0);
pD3DDevice->BeginScene();
pD3DDevice->EndScene();
pD3DDevice-> resent(NULL,NULL,NUL,NULL);
}
void CleanUp()
{
if(pD3DDevice !=NULL)
{
pD3DDevice->Release();
pD3DDevice = NULL;
}
}
void GameLoop()
{
//Enter the game loop
MSG msg;
BOOL fMessage;
PeekMessage(&msg, NULL, 0U, 0U, PM_NOREMOVE);
while(msg.message != WM_QUIT)
{
fMessage = PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE);
if(fMessage)
{
//Process message
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
//No message to process, so render the current scene
Render();
}
}
}
//The windows message handler
LRESULT WINAPI WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
break;
case WM_KEYUP:
switch (wParam)
{
case VK_ESCAPE:
//User has pressed the escape key, so quit
DestroyWindow(hWnd);
return 0;
break;
}
break;
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}
|
|