头文件:
#include <windows.h>
#include <d3d11.h>
#include <d3dx11.h>
#include "resource.h"
全局变量声明:
// Global Variables
HINSTANCE g_hInst = NULL; //实例句柄
HWND g_hWnd = NULL; //窗口句柄
D3D_DRIVER_TYPE g_driverType = D3D_DRIVER_TYPE_NULL; //驱动类型
D3D_FEATURE_LEVEL g_featureLevel = D3D_FEATURE_LEVEL_11_0; //特征等级
ID3D11Device* g_pd3dDevice = NULL; //设备接口指针
ID3D11DeviceContext* g_pImmediateContext = NULL; //设备上下文接口指针
IDXGISwapChain* g_pSwapChain = NULL; //交换链接口指针
ID3D11RenderTargetView* g_pRenderTargetView = NULL; //渲染目标视图接口指针
函数声明:
// Forward declarations
HRESULT InitWindow( HINSTANCE hInstance, int nCmdShow ); //窗口初始化函数
HRESULT InitDevice(); //设备初始化函数
void CleanupDevice(); //清除设备函数
LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM ); //窗口过程函数
void Render(); //渲染函数
程序入口点函数:
int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow )
{
UNREFERENCED_PARAMETER( hPrevInstance );
UNREFERENCED_PARAMETER( lpCmdLine );
// 窗口初始化
if( FAILED( InitWindow( hInstance, nCmdShow ) ) )
return 0;
// 设备初始化
if( FAILED( InitDevice() ) )
{
CleanupDevice();
return 0;
}
// 消息主循环
// Main message loop
MSG msg = {
0};
while( WM_QUIT != msg.message )