本文属于《逐梦旅程》学习笔记系列的DirectX篇,与此系列的Windows/GDI并列。
本系列不打算深入研究DirectX而只是简单介绍DirectX中应用最广泛的部分:Direct3D
作为本篇的开篇,我们用一个最简化的示例来说明。
这个示例的完整代码可以在这里找到
https://github.com/fengyhack/DirectGame/tree/SimpleDemo
首先,Windows Application的主函数WinMain具有如下结构
App app;
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nShowCmd)
{
LPCSTR lpsz = "DemoWindow";
HWND hwnd = CreateSimpleWindow(hInstance, lpsz, WndProc);
ShowWindow(hwnd, nShowCmd);
UpdateWindow(hwnd);
PlaySound("NOIR3.wav", NULL, SND_FILENAME | SND_ASYNC | SND_LOOP); //循环播放背景音乐
app.Create(hwnd);
MSG msg = { 0 };
while (msg.message != WM_QUIT)
{
if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
app.Render();
}
}
UnregisterClass(lpsz, hInstance);
return 0;
}
基本上就是这几步