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
|
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZRHW|D3DFVF_DIFFUSE)
void Engine::OnCreate(HWND hWnd) {
OwnerHandle = hWnd;
// A custom class, takes X, Y, WIDTH, HEIGHT, Z, RHW, COLOR parameters. It creates appropriate vertex information based off those parameters.
TEST_BOX.Initialize(100, 100, 1400, 1400, 1, 0.5, 0xff00ffff);
DX9Interface = Direct3DCreate9(D3D_SDK_VERSION);
D3DPRESENT_PARAMETERS DX9Params;
ZeroMemory(&DX9Params, sizeof(DX9Params));
DX9Params.Windowed = true;
DX9Params.BackBufferWidth = 1920;
DX9Params.BackBufferHeight = 1080;
DX9Params.SwapEffect = D3DSWAPEFFECT_DISCARD;
DX9Params.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; // VSYNC OFF = D3DPRESENT_INTERVAL_IMMEDIATE, VSYNC ON = D3DPRESENT_INTERVAL_DEFAULT
DX9Params.hDeviceWindow = OwnerHandle;
DX9Params.MultiSampleType = D3DMULTISAMPLE_8_SAMPLES;
if (FAILED(DX9Interface->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, OwnerHandle, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &DX9Params, &DX9Device))) {
MessageBox(NULL, L"Failed to initialize DirectX device.", L"DirectX", MB_OK | MB_ICONERROR);
exit(2);
}
DX9Device->SetRenderState(D3DRS_MULTISAMPLEANTIALIAS, true);
LPDIRECT3DVERTEXBUFFER9 g_pVB;
DX9Device->CreateVertexBuffer(3* sizeof(TEST_BOX.Vertices), D3DUSAGE_WRITEONLY, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &g_pVB, NULL);
VOID* pVertices;
g_pVB->Lock( 0, sizeof(TEST_BOX.Vertices), (void**)&pVertices, 0);
memcpy(pVertices, TEST_BOX.Vertices, sizeof(TEST_BOX.Vertices));
DX9Device->SetStreamSource(0, g_pVB, 0, sizeof(UI::Vertex));
DX9Device->SetFVF(D3DFVF_CUSTOMVERTEX);
g_pVB->Unlock();
g_pVB->Release();
Initialized = true;
}
|