1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
/**************/
/* Main.cpp */
/**************/
#include <Windows.h>
#include "System.h"
#include <d3d9.h>
#include <d3dx9.h>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
System EngineWindow(hInstance);
if(!EngineWindow.InitializeWindow()) { return -1; }
//Define Direct3D interfaces and Present_Parameter
IDirect3D9* pd3d;
IDirect3DDevice9* d3dDevice;
D3DPRESENT_PARAMETERS d3dpp;
HRESULT hr;
//Set the interfaces to zero and zero present_parameters memory
pd3d = NULL;
d3dDevice = NULL;
ZeroMemory(&d3dpp, sizeof(D3DPRESENT_PARAMETERS));
//Create D3D Object
pd3d = Direct3DCreate9(D3D_SDK_VERSION);
if(!pd3d) { MessageBox(NULL, "Error Creating pd3d Interface", "D3D Error", MB_OK); return -3; }
try {
d3dpp.BackBufferCount = 1;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
d3dpp.BackBufferHeight = 640;
d3dpp.BackBufferWidth = 480;
d3dpp.hDeviceWindow = EngineWindow.GetHwnd();
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;
d3dpp.Windowed = true;
} catch(...) {
MessageBox(NULL, "Error in Present Parameters", "Error", MB_OK);
return -3;
}
D3DCAPS9 caps;
DWORD behavior; //After figuring out hardware support, behavior object will be used when creating d3dDevice
hr = pd3d->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &caps);
//Chreak for hardware transform and lighting support
if((caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) == FALSE || caps.VertexShaderVersion < D3DVS_VERSION(1,1)) {
behavior = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
} else {
behavior = D3DCREATE_HARDWARE_VERTEXPROCESSING;
}
//Create Device
hr = pd3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
EngineWindow.GetHwnd(), behavior, &d3dpp, &d3dDevice);
//Check for failure
if(FAILED(hr)) {
MessageBox(NULL, "Failed to create D3DDevice", "D3D Error", MB_OK);
return -3;
}
// ************Rendering Function**************
d3dDevice->Clear(NULL, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 0.0f, 0);
//You Draw Stuff in between these two statments
d3dDevice->Present(NULL, NULL, NULL, NULL);
EngineWindow.Run(true);
//Destructure
if(d3dDevice) d3dDevice->Release(); d3dDevice = NULL; //Release and set to NULL
if(pd3d) pd3d->Release(); pd3d = NULL; //Relase and set to NULL
return 0; //static_cast<int>( msg.wParam );
}
|