HRESULT InitObject(void) { srand(unsigned(time(NULL))); if (FAILED(D3DXCreateFont(g_pDevice, 30, 0, 0, 1, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, 0, TEXT("宋体"), &g_pFont))) { return E_FAIL; } if (FAILED(g_pDevice->CreateVertexBuffer(8 * sizeof(CUSTOMVERTEX) , 0 , D3DFVF_CUSTOMVERTEX , D3DPOOL_DEFAULT , &g_pVertexBuffer , NULL))) { return E_FAIL; } if (FAILED(g_pDevice->CreateIndexBuffer(36 * sizeof(WORD) , 0 , D3DFMT_INDEX16 , D3DPOOL_DEFAULT , &g_pIndexBuffer , NULL))) { return E_FAIL; } ChangeObject(); return S_OK; }
PLbool VboManager::ChangeSprite2D(VboObject* object, PLfloat left, PLfloat top, PLfloat right, PLfloat bottom) { TVertex2f data[6] = { TVertex2f(left, top), TVertex2f(right, top), TVertex2f(left, bottom), TVertex2f(right, bottom), TVertex2f(left, bottom), TVertex2f(right, top) }; return ChangeObject(object, data, sizeof(data)); }
PLbool VboManager::ChangeBillboard(VboObject* object, PLfloat left, PLfloat top, PLfloat right, PLfloat bottom, PLfloat depth_lt, PLfloat depth_lb, PLfloat depth_rt, PLfloat depth_rb) { TVertex3f data[6] = { TVertex3f(left, top, depth_lt), TVertex3f(right, top, depth_rt), TVertex3f(left, bottom, depth_lb), TVertex3f(right, bottom, depth_rb), TVertex3f(left, bottom, depth_lb), TVertex3f(right, top, depth_rt) }; return ChangeObject(object, data, sizeof(data)); }
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_CREATE: { if (FAILED(InitD3D(hWnd))) { MessageBox(hWnd, TEXT("Initialize DirectX failed"), TEXT("警告"), MB_OK | MB_ICONERROR); PostQuitMessage(0); } break; } case WM_PAINT: Render(hWnd); ValidateRect(hWnd, NULL); break; case WM_KEYDOWN: if (wParam == VK_ESCAPE) { DestroyWindow(hWnd); } else { ChangeObject(); } break; case WM_SIZE: OnSize((short)LOWORD(lParam), (short)HIWORD(lParam)); break; case WM_DESTROY: Cleanup(); PostQuitMessage(0); break; default: return ::DefWindowProc(hWnd, uMsg, wParam, lParam); } return 0; }