master 3beef5878a9c cached
111 files
696.2 KB
240.7k tokens
419 symbols
1 requests
Download .txt
Showing preview only (767K chars total). Download the full file or copy to clipboard to get everything.
Repository: QianMo/Direct3D-Win32-Book-Src-Code
Branch: master
Commit: 3beef5878a9c
Files: 111
Total size: 696.2 KB

Directory structure:
gitextract_izccgwl9/

├── .gitattributes
├── .gitignore
├── Direct3D-Game-Demo/
│   ├── D3Ddemo0/
│   │   └── D3DdemoCore.cpp
│   ├── D3Ddemo1/
│   │   └── D3Ddemo1.cpp
│   ├── D3Ddemo10/
│   │   ├── D3DUtil.h
│   │   ├── D3Ddemo10.cpp
│   │   ├── DirectInputClass.cpp
│   │   └── DirectInputClass.h
│   ├── D3Ddemo11/
│   │   ├── D3DUtil.h
│   │   ├── D3Ddemo11.cpp
│   │   ├── DirectInputClass.cpp
│   │   └── DirectInputClass.h
│   ├── D3Ddemo12/
│   │   ├── D3DUtil.h
│   │   ├── D3Ddemo12.cpp
│   │   ├── DirectInputClass.cpp
│   │   └── DirectInputClass.h
│   ├── D3Ddemo13/
│   │   ├── D3DUtil.h
│   │   ├── D3Ddemo13.cpp
│   │   ├── DirectInputClass.cpp
│   │   └── DirectInputClass.h
│   ├── D3Ddemo14/
│   │   ├── D3DUtil.h
│   │   ├── D3Ddemo14.cpp
│   │   ├── DirectInputClass.cpp
│   │   └── DirectInputClass.h
│   ├── D3Ddemo15/
│   │   ├── D3DUtil.h
│   │   ├── D3Ddemo15.cpp
│   │   ├── DirectInputClass.cpp
│   │   └── DirectInputClass.h
│   ├── D3Ddemo16/
│   │   ├── CameraClass.cpp
│   │   ├── CameraClass.h
│   │   ├── D3DUtil.h
│   │   ├── D3Ddemo16.cpp
│   │   ├── DirectInputClass.cpp
│   │   └── DirectInputClass.h
│   ├── D3Ddemo17/
│   │   ├── CameraClass.cpp
│   │   ├── CameraClass.h
│   │   ├── D3DUtil.h
│   │   ├── D3Ddemo17.cpp
│   │   ├── DirectInputClass.cpp
│   │   ├── DirectInputClass.h
│   │   ├── TerrainClass.cpp
│   │   └── TerrainClass.h
│   ├── D3Ddemo18/
│   │   ├── CameraClass.cpp
│   │   ├── CameraClass.h
│   │   ├── D3DUtil.h
│   │   ├── D3Ddemo18.cpp
│   │   ├── DirectInputClass.cpp
│   │   ├── DirectInputClass.h
│   │   ├── SkyBoxClass.cpp
│   │   ├── SkyBoxClass.h
│   │   ├── TerrainClass.cpp
│   │   └── TerrainClass.h
│   ├── D3Ddemo19/
│   │   ├── CameraClass.cpp
│   │   ├── CameraClass.h
│   │   ├── D3DUtil.h
│   │   ├── D3Ddemo19.cpp
│   │   ├── DirectInputClass.cpp
│   │   ├── DirectInputClass.h
│   │   ├── SkyBoxClass.cpp
│   │   ├── SkyBoxClass.h
│   │   ├── SnowParticleClass.cpp
│   │   ├── SnowParticleClass.h
│   │   ├── TerrainClass.cpp
│   │   └── TerrainClass.h
│   ├── D3Ddemo2/
│   │   └── D3Ddemo2.cpp
│   ├── D3Ddemo20/
│   │   ├── CameraClass.cpp
│   │   ├── CameraClass.h
│   │   ├── D3DUtil.h
│   │   ├── D3Ddemo20.cpp
│   │   ├── DirectInputClass.cpp
│   │   ├── DirectInputClass.h
│   │   ├── SkyBoxClass.cpp
│   │   ├── SkyBoxClass.h
│   │   ├── SnowParticleClass.cpp
│   │   ├── SnowParticleClass.h
│   │   ├── TerrainClass.cpp
│   │   ├── TerrainClass.h
│   │   ├── XFileModelClass.cpp
│   │   └── XFileModelClass.h
│   ├── D3Ddemo3/
│   │   └── D3Ddemo3.cpp
│   ├── D3Ddemo4/
│   │   └── D3Ddemo4.cpp
│   ├── D3Ddemo5/
│   │   └── D3Ddemo5.cpp
│   ├── D3Ddemo6/
│   │   └── D3Ddemo6.cpp
│   ├── D3Ddemo7/
│   │   └── D3Ddemo7.cpp
│   ├── D3Ddemo8/
│   │   └── D3Ddemo8.cpp
│   └── D3Ddemo9/
│       ├── D3DUtil.h
│       ├── D3Ddemo9.cpp
│       ├── DirectInputClass.cpp
│       └── DirectInputClass.h
├── GDI-Game-Demo/
│   ├── 10_GDIdemo6.cpp
│   ├── 11_GDIdemo7.cpp
│   ├── 12_GDIdemo8.cpp
│   ├── 13_GDIdemo9.cpp
│   ├── 14_GDIdemo10.cpp
│   ├── 15_GDIdemo11.cpp
│   ├── 16_GDIdemo12.cpp
│   ├── 17_GDIdemo13.cpp
│   ├── 18_GDIdemo14.cpp
│   ├── 19_GDIdemo15.cpp
│   ├── 1_HelloVisualStudio.cpp
│   ├── 20_GDIdemo16.cpp
│   ├── 21_GDIdemo17.cpp
│   ├── 2_FirstBlood!.cpp
│   ├── 3_GameCore.cpp
│   ├── 4_GDIdemoCore.cpp
│   ├── 5_GDIdemo1.cpp
│   ├── 6_GDIdemo2.cpp
│   ├── 7_GDIdemo3.cpp
│   ├── 8_GDIdemo4.cpp
│   └── 9_GDIdemo5.cpp
└── README.md

================================================
FILE CONTENTS
================================================

================================================
FILE: .gitattributes
================================================
# Auto detect text files and perform LF normalization
* text=auto

# Custom for Visual Studio
*.cs     diff=csharp

# Standard to msysgit
*.doc	 diff=astextplain
*.DOC	 diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot  diff=astextplain
*.DOT  diff=astextplain
*.pdf  diff=astextplain
*.PDF	 diff=astextplain
*.rtf	 diff=astextplain
*.RTF	 diff=astextplain


================================================
FILE: .gitignore
================================================
# Windows image file caches
Thumbs.db
ehthumbs.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msm
*.msp

# Windows shortcuts
*.lnk

# =========================
# Operating System Files
# =========================

# OSX
# =========================

.DS_Store
.AppleDouble
.LSOverride

# Thumbnails
._*

# Files that might appear on external disk
.Spotlight-V100
.Trashes

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk


================================================
FILE: Direct3D-Game-Demo/D3Ddemo0/D3DdemoCore.cpp
================================================

//-----------------------------------˵----------------------------------------------
//  :D3DdemoCore
//	 20134 Create by dzī
//  Direct3DĺĿ
//------------------------------------------------------------------------------------------------

//-----------------------------------ͷļ֡---------------------------------------
//	ͷļ
//------------------------------------------------------------------------------------------------
#include <d3d9.h>

//-----------------------------------ļ֡---------------------------------------
//	Ŀļ
//------------------------------------------------------------------------------------------------
#pragma comment(lib,"winmm.lib")  //PlaySoundļ

//-----------------------------------궨岿֡--------------------------------------------
//	һЩ
//------------------------------------------------------------------------------------------------
#define WINDOW_WIDTH	800							//Ϊڿȶĺ꣬Էڴ˴޸Ĵڿ
#define WINDOW_HEIGHT	600							//Ϊڸ߶ȶĺ꣬Էڴ˴޸Ĵڸ߶
#define WINDOW_TITLE	L"ϨϷ롿Direct3DĺĿ"	//Ϊڱⶨĺ
#define SAFE_RELEASE(p) { if(p) { (p)->Release(); (p)=NULL; } }   //һȫͷź꣬ںCOMӿָͷ

//-----------------------------------ȫֱ֡-------------------------------------
//	ȫֱ
//------------------------------------------------------------------------------------------------

//-----------------------------------ȫֺ֡-------------------------------------
//	ȫֺֹδıʶϵд
//------------------------------------------------------------------------------------------------
LRESULT CALLBACK	WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam );//ڹ̺
HRESULT					Direct3D_Init(HWND hwnd);		 //нDirect3Dijʼ
HRESULT					Objects_Init(HWND hwnd); 		//нҪƵԴʼ
VOID							Direct3D_Render(HWND hwnd); 	//нDirect3DȾд
VOID							Direct3D_CleanUp( );				//COMԴԼԴ

//-----------------------------------WinMain( )--------------------------------------
//	WindowsӦóںǵij↑ʼ
//------------------------------------------------------------------------------------------------
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nShowCmd)
{
	//1ڴIJ֮һʼһĴ
	WNDCLASSEX wndClass = { 0 };							//WINDCLASSEXһ
	wndClass.cbSize = sizeof( WNDCLASSEX ) ;			//ýṹֽС
	wndClass.style = CS_HREDRAW | CS_VREDRAW;	//ôڵʽ
	wndClass.lpfnWndProc = WndProc;					//ָ򴰿ڹָ̺
	wndClass.cbClsExtra		= 0;								//ĸڴ棬ȡ0Ϳ
	wndClass.cbWndExtra		= 0;							//ڵĸڴ棬Ȼȡ0
	wndClass.hInstance = hInstance;						//ָڹ̵ijʵ
	wndClass.hIcon=(HICON)::LoadImage(NULL,L"icon.ico",IMAGE_ICON,0,0,LR_DEFAULTSIZE|LR_LOADFROMFILE);  //ؼԶicoͼ
	wndClass.hCursor = LoadCursor( NULL, IDC_ARROW );    //ָĹ
	wndClass.hbrBackground=(HBRUSH)GetStockObject(GRAY_BRUSH);  //ΪhbrBackgroundԱָһɫˢ	
	wndClass.lpszMenuName = NULL;						//һԿַָֹ˵Դ֡
	wndClass.lpszClassName = L"ForTheDreamOfGameDevelop";		//һԿַָֹ֡

	//2ڴIJ֮עᴰ
	if( !RegisterClassEx( &wndClass ) )				//괰ںҪԴעᣬܴ͵Ĵ
		return -1;		

	//3ڴIJ֮ʽ
	HWND hwnd = CreateWindow( L"ForTheDreamOfGameDevelop",WINDOW_TITLE,				//ϲּĴںCreateWindow
		WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, WINDOW_WIDTH,
		WINDOW_HEIGHT, NULL, NULL, hInstance, NULL );

	//Direct3DԴijʼ
	Direct3D_Init (hwnd);   

	//4ڴIJ֮ģڵƶʾ
	MoveWindow(hwnd,250,80,WINDOW_WIDTH,WINDOW_HEIGHT,true);		//ʾʱλãʹϽλڣ250,80
	ShowWindow( hwnd, nShowCmd );    //ShowWindowʾ
	UpdateWindow(hwnd);						//Դڽи£·Ҫװһ



	PlaySound(L"War3XMainScreen.wav", NULL, SND_FILENAME | SND_ASYNC|SND_LOOP); //ѭű 
	MessageBox(hwnd, L"DirectXưɣ~!", L"dzīϢ", 0); //ʹMessageBoxʾһϢ

	//5Ϣѭ
	MSG msg = { 0 };  //ʼmsg
	while( msg.message != WM_QUIT )			//ʹwhileѭ
	{
		if( PeekMessage( &msg, 0, 0, 0, PM_REMOVE ) )   //鿴ӦóϢУϢʱеϢɷȥ
		{
			TranslateMessage( &msg );		//ϢתΪַϢ
			DispatchMessage( &msg );		//úַһϢڳ
		}
		else
		{
			Direct3D_Render(hwnd);   //Ⱦ
		}
	}
	//6ע
	UnregisterClass(L"ForTheDreamOfGameDevelop", wndClass.hInstance);  //׼ע
	return 0;  
}

//-----------------------------------WndProc( )--------------------------------------
//	ڹ̺WndProc,ԴϢд
//------------------------------------------------------------------------------------------------
LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )      
{
	switch( message )						//switch俪ʼ
	{
	case WM_PAINT:						// ǿͻػϢ
		Direct3D_Render(hwnd);                 //Direct3DȾ
		ValidateRect(hwnd, NULL);		// ¿ͻʾ
		break;									//switch

	case WM_KEYDOWN:					// Ǽ̰Ϣ
		if (wParam == VK_ESCAPE)    // µļESC
			DestroyWindow(hwnd);		// ٴ, һWM_DESTROYϢ
		break;									//switch

	case WM_DESTROY:					//ǴϢ
		Direct3D_CleanUp();			//ԶԴGame_CleanUp˳ǰԴ
		PostQuitMessage( 0 );			//ϵͳиֹ߳ӦWM_DESTROYϢ
		break;									//switch

	default:										//caseϣִиdefault
		return DefWindowProc( hwnd, message, wParam, lParam );		//ȱʡĴڹ
	}

	return 0;									//˳
}

//-----------------------------------Direct3D_Init( )--------------------------------------
//	Direct3DʼDirect3Dijʼ
//------------------------------------------------------------------------------------------------
HRESULT Direct3D_Init(HWND hwnd)
{
	 if(!(S_OK==Objects_Init(hwnd))) return E_FAIL;     //һObjects_InitȾԴijʼ
	return S_OK;
}



//-----------------------------------Object_Init( )--------------------------------------
//	ȾԴʼڴ˺нҪȾԴijʼ
//--------------------------------------------------------------------------------------------------
HRESULT Objects_Init(HWND hwnd)
{
	return S_OK;
}


//-----------------------------------Direct3D_Render( )--------------------------------------
//	ʹDirect3DȾ
//--------------------------------------------------------------------------------------------------
void Direct3D_Render(HWND hwnd)
{
	//ʱΪգ»طֽ
}


//-----------------------------------Direct3D_CleanUp( )--------------------------------
//	Դڴ˺нг˳ǰԴ
//---------------------------------------------------------------------------------------------------
void Direct3D_CleanUp()
{
	//ʱΪգ»طֽ
}


================================================
FILE: Direct3D-Game-Demo/D3Ddemo1/D3Ddemo1.cpp
================================================

//-----------------------------------˵----------------------------------------------
//  :D3Ddemo1
//	 20134 Create by dzī
//  Direct3DʼIJ ʾ
//------------------------------------------------------------------------------------------------

//-----------------------------------ͷļ֡---------------------------------------
//	ͷļ
//------------------------------------------------------------------------------------------------
#include <d3d9.h>

//-----------------------------------ļ֡---------------------------------------
//	Ŀļ
//------------------------------------------------------------------------------------------------
#pragma comment(lib,"winmm.lib")  //PlaySoundļ
#pragma comment(lib,"d3d9.lib")
#pragma comment(lib,"d3dx9.lib")

//-----------------------------------궨岿֡--------------------------------------------
//	һЩ
//------------------------------------------------------------------------------------------------
#define WINDOW_WIDTH	800							//Ϊڿȶĺ꣬Էڴ˴޸Ĵڿ
#define WINDOW_HEIGHT	600							//Ϊڸ߶ȶĺ꣬Էڴ˴޸Ĵڸ߶
#define WINDOW_TITLE	L"ϨϷ롿Direct3DʼIJ ʾ"	//Ϊڱⶨĺ
#define SAFE_RELEASE(p) { if(p) { (p)->Release(); (p)=NULL; } }   //һȫͷź꣬ںCOMӿָͷ

//-----------------------------------ȫֱ֡-------------------------------------
//	ȫֱ
//------------------------------------------------------------------------------------------------
LPDIRECT3DDEVICE9       g_pd3dDevice = NULL; //Direct3D豸


//-----------------------------------ȫֺ֡-------------------------------------
//	ȫֺֹδıʶϵд
//------------------------------------------------------------------------------------------------
LRESULT CALLBACK	WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam );//ڹ̺
HRESULT					Direct3D_Init(HWND hwnd);		 //нDirect3Dijʼ
HRESULT					Objects_Init(HWND hwnd); 		//нҪƵԴʼ
VOID							Direct3D_Render(HWND hwnd); 	//нDirect3DȾд
VOID							Direct3D_CleanUp( );				//COMԴԼԴ

//-----------------------------------WinMain( )--------------------------------------
//	WindowsӦóںǵij↑ʼ
//------------------------------------------------------------------------------------------------
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nShowCmd)
{
	//1ڴIJ֮һʼһĴ
	WNDCLASSEX wndClass = { 0 };							//WINDCLASSEXһ
	wndClass.cbSize = sizeof( WNDCLASSEX ) ;			//ýṹֽС
	wndClass.style = CS_HREDRAW | CS_VREDRAW;	//ôڵʽ
	wndClass.lpfnWndProc = WndProc;					//ָ򴰿ڹָ̺
	wndClass.cbClsExtra		= 0;								//ĸڴ棬ȡ0Ϳ
	wndClass.cbWndExtra		= 0;							//ڵĸڴ棬Ȼȡ0
	wndClass.hInstance = hInstance;						//ָڹ̵ijʵ
	wndClass.hIcon=(HICON)::LoadImage(NULL,L"icon.ico",IMAGE_ICON,0,0,LR_DEFAULTSIZE|LR_LOADFROMFILE);  //ؼԶicoͼ
	wndClass.hCursor = LoadCursor( NULL, IDC_ARROW );    //ָĹ
	wndClass.hbrBackground=(HBRUSH)GetStockObject(GRAY_BRUSH);  //ΪhbrBackgroundԱָһɫˢ	
	wndClass.lpszMenuName = NULL;						//һԿַָֹ˵Դ֡
	wndClass.lpszClassName = L"ForTheDreamOfGameDevelop";		//һԿַָֹ֡

	//2ڴIJ֮עᴰ
	if( !RegisterClassEx( &wndClass ) )				//괰ںҪԴעᣬܴ͵Ĵ
		return -1;		

	//3ڴIJ֮ʽ
	HWND hwnd = CreateWindow( L"ForTheDreamOfGameDevelop",WINDOW_TITLE,				//ϲּĴںCreateWindow
		WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, WINDOW_WIDTH,
		WINDOW_HEIGHT, NULL, NULL, hInstance, NULL );

	//Direct3DԴijʼɹʧܶmessageboxʾ
	if (S_OK==Direct3D_Init (hwnd))
	{
		MessageBox(hwnd, L"Direct3Dʼ~", L"dzīϢ", 0); //ʹMessageBoxһϢ  
	}
	else
	{
		MessageBox(hwnd, L"Direct3Dʼʧ~", L"dzīϢ", 0); //ʹMessageBoxһϢ 
	}

	//4ڴIJ֮ģڵƶʾ
	MoveWindow(hwnd,250,80,WINDOW_WIDTH,WINDOW_HEIGHT,true);		//ʾʱλãʹϽλڣ250,80
	ShowWindow( hwnd, nShowCmd );    //ShowWindowʾ
	UpdateWindow(hwnd);						//Դڽи£·Ҫװһ


	PlaySound(L"NightElf3.wav", NULL, SND_FILENAME | SND_ASYNC|SND_LOOP); //ѭű 

	//5Ϣѭ
	MSG msg = { 0 };  //ʼmsg
	while( msg.message != WM_QUIT )			//ʹwhileѭ
	{
		if( PeekMessage( &msg, 0, 0, 0, PM_REMOVE ) )   //鿴ӦóϢУϢʱеϢɷȥ
		{
			TranslateMessage( &msg );		//ϢתΪַϢ
			DispatchMessage( &msg );		//úַһϢڳ
		}
		else
		{
			Direct3D_Render(hwnd);   //Ⱦ
		}
	}
	//6ע
	UnregisterClass(L"ForTheDreamOfGameDevelop", wndClass.hInstance);  //׼ע
	return 0;  
}

//-----------------------------------WndProc( )--------------------------------------
//	ڹ̺WndProc,ԴϢд
//------------------------------------------------------------------------------------------------
LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )      
{
	switch( message )						//switch俪ʼ
	{
	case WM_PAINT:						// ǿͻػϢ
		Direct3D_Render(hwnd);                 //Direct3DȾ
		ValidateRect(hwnd, NULL);		// ¿ͻʾ
		break;									//switch

	case WM_KEYDOWN:					// Ǽ̰Ϣ
		if (wParam == VK_ESCAPE)    // µļESC
			DestroyWindow(hwnd);		// ٴ, һWM_DESTROYϢ
		break;									//switch

	case WM_DESTROY:					//ǴϢ
		Direct3D_CleanUp();			//ԶԴGame_CleanUp˳ǰԴ
		PostQuitMessage( 0 );			//ϵͳиֹ߳ӦWM_DESTROYϢ
		break;									//switch

	default:										//caseϣִиdefault
		return DefWindowProc( hwnd, message, wParam, lParam );		//ȱʡĴڹ
	}

	return 0;									//˳
}

//-----------------------------------Direct3D_Init( )--------------------------------------
//	Direct3DʼDirect3Dijʼ
//------------------------------------------------------------------------------------------------
HRESULT Direct3D_Init(HWND hwnd)
{
	//--------------------------------------------------------------------------------------
	// Direct3DʼIJ֮һӿڡDirect3Dӿڶ, ԱøDirect3D󴴽Direct3D豸
	//--------------------------------------------------------------------------------------
	LPDIRECT3D9  pD3D = NULL; //Direct3DӿڶĴ
	if( NULL == ( pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) ) //ʼDirect3Dӿڶ󣬲DirectX汾Э
		return E_FAIL;

	//--------------------------------------------------------------------------------------
	// Direct3DʼIJ֮,ȡϢȡӲ豸Ϣ
	//--------------------------------------------------------------------------------------
	D3DCAPS9 caps; int vp = 0;
	if( FAILED( pD3D->GetDeviceCaps( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &caps ) ) )
	{
		return E_FAIL;
	}
	if( caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT )
		vp = D3DCREATE_HARDWARE_VERTEXPROCESSING;   //֧Ӳ㣬ǾͲӲ㣬׵
	else
		vp = D3DCREATE_SOFTWARE_VERTEXPROCESSING; //֧Ӳ㣬ֻò

	//--------------------------------------------------------------------------------------
	// Direct3DʼIJ֮ݡD3DPRESENT_PARAMETERSṹ
	//--------------------------------------------------------------------------------------
	D3DPRESENT_PARAMETERS d3dpp; 
	ZeroMemory(&d3dpp, sizeof(d3dpp));
	d3dpp.BackBufferWidth            = WINDOW_WIDTH;
	d3dpp.BackBufferHeight           = WINDOW_HEIGHT;
	d3dpp.BackBufferFormat           = D3DFMT_A8R8G8B8;
	d3dpp.BackBufferCount            = 1;
	d3dpp.MultiSampleType            = D3DMULTISAMPLE_NONE;
	d3dpp.MultiSampleQuality         = 0;
	d3dpp.SwapEffect                 = D3DSWAPEFFECT_DISCARD; 
	d3dpp.hDeviceWindow              = hwnd;
	d3dpp.Windowed                   = true;
	d3dpp.EnableAutoDepthStencil     = true; 
	d3dpp.AutoDepthStencilFormat     = D3DFMT_D24S8;
	d3dpp.Flags                      = 0;
	d3dpp.FullScreen_RefreshRateInHz = 0;
	d3dpp.PresentationInterval       = D3DPRESENT_INTERVAL_IMMEDIATE;

	//--------------------------------------------------------------------------------------
	// Direct3DʼIJ֮ģ豸Direct3D豸ӿ
	//--------------------------------------------------------------------------------------
	if(FAILED(pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, 
		hwnd, vp, &d3dpp, &g_pd3dDevice)))
		return E_FAIL;

	SAFE_RELEASE(pD3D) //LPDIRECT3D9ӿڶʹɣǽͷŵ


	if(!(S_OK==Objects_Init(hwnd))) return E_FAIL;     //һObjects_InitȾԴijʼ
	return S_OK;
}



//-----------------------------------Object_Init( )--------------------------------------
//	ȾԴʼڴ˺нҪȾԴijʼ
//--------------------------------------------------------------------------------------------------
HRESULT Objects_Init(HWND hwnd)
{
	return S_OK;
}


//-----------------------------------Direct3D_Render( )--------------------------------------
//	ʹDirect3DȾ
//--------------------------------------------------------------------------------------------------
void Direct3D_Render(HWND hwnd)
{
	//ʱΪգ»طֽ
}


//-----------------------------------Direct3D_CleanUp( )--------------------------------
//	Դڴ˺нг˳ǰԴ
//---------------------------------------------------------------------------------------------------
void Direct3D_CleanUp()
{
	//ʱΪգ»طֽ
}


================================================
FILE: Direct3D-Game-Demo/D3Ddemo10/D3DUtil.h
================================================

//=============================================================================
// Desc: D3DUtil.hͷļڹĶ
// 2013 203  Create by dzī 
//=============================================================================

#pragma once


#ifndef HR
#define HR(x)    { hr = x; if( FAILED(hr) ) { return hr; } }         //ԶһHRִ꣬дķ
#endif

#ifndef SAFE_DELETE					
#define SAFE_DELETE(p)       { if(p) { delete (p);     (p)=NULL; } }       //ԶһSAFE_RELEASE(),ָԴͷ
#endif    

#ifndef SAFE_RELEASE			
#define SAFE_RELEASE(p)      { if(p) { (p)->Release(); (p)=NULL; } }     //ԶһSAFE_RELEASE(),COMԴͷ
#endif

================================================
FILE: Direct3D-Game-Demo/D3Ddemo10/D3Ddemo10.cpp
================================================
//-----------------------------------˵----------------------------------------------
//  :D3Ddemo10
//	 20134 Create by dzī
//  Ϊάʣӳ ʾ֮һ
//  ͼ꼰ͼƬزģ ɽǰ 
//------------------------------------------------------------------------------------------------


//-----------------------------------궨岿֡--------------------------------------------
// һЩ
//------------------------------------------------------------------------------------------------
#define WINDOW_WIDTH	800						//Ϊڿȶĺ꣬Էڴ˴޸Ĵڿ
#define WINDOW_HEIGHT	600							//Ϊڸ߶ȶĺ꣬Էڴ˴޸Ĵڸ߶
#define WINDOW_TITLE	_T("ϨϷ롿Ϊάʣӳ ʾ֮һ") //Ϊڱⶨĺ



//-----------------------------------ͷļ֡---------------------------------------
//	ͷļ
//------------------------------------------------------------------------------------------------                                                                                     
#include <d3d9.h>
#include <d3dx9.h>
#include <tchar.h>
#include <time.h> 
#include "DirectInputClass.h"



//-----------------------------------ļ֡---------------------------------------
//	Ŀļ
//------------------------------------------------------------------------------------------------
#pragma comment(lib,"d3d9.lib")
#pragma comment(lib,"d3dx9.lib")
#pragma comment(lib, "dinput8.lib")     // ʹDirectInputͷļע8
#pragma comment(lib,"dxguid.lib")
#pragma comment(lib, "winmm.lib") 


//--------------------------------------------------------------------------------------
// IJ֮һĶ	
//--------------------------------------------------------------------------------------
struct CUSTOMVERTEX 
{
	FLOAT _x, _y, _z;               // λ
	FLOAT _u, _v;                   // 
	CUSTOMVERTEX(FLOAT x, FLOAT y, FLOAT z, FLOAT u, FLOAT v)
		: _x(x), _y(y), _z(z), _u(u), _v(v) {}
};
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ | D3DFVF_TEX1)

//-----------------------------------ȫֱ֡-------------------------------------
//	ȫֱ
//------------------------------------------------------------------------------------------------
LPDIRECT3DDEVICE9					g_pd3dDevice = NULL; //Direct3D豸
LPD3DXFONT								g_pTextFPS				=NULL;    //COMӿ
LPD3DXFONT								g_pTextAdaperName           = NULL;  // ԿϢ2Dı
LPD3DXFONT								g_pTextHelper          = NULL;  // Ϣ2Dı
LPD3DXFONT								g_pTextInfor           = NULL;  // Ϣ2Dı
float											g_FPS								= 0.0f;       //һ͵ı֡
wchar_t										g_strFPS[50]={0};    //֡ʵַ
wchar_t										g_strAdapterName[60]={0};    //ԿƵַ
D3DXMATRIX							g_matWorld;   //
LPDIRECT3DVERTEXBUFFER9		g_pVertexBuffer = NULL;    //㻺
LPDIRECT3DINDEXBUFFER9		g_pIndexBuffer  = NULL;    // 
LPDIRECT3DTEXTURE9				g_pTexture   = NULL;    // ӿڶ
DInputClass*								g_pDInput = NULL;         //һDInputClassָ

//-----------------------------------ȫֺ֡-------------------------------------
//	ȫֺֹδıʶϵд
//------------------------------------------------------------------------------------------------
LRESULT CALLBACK		WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam );
HRESULT						Direct3D_Init(HWND hwnd,HINSTANCE hInstance);
HRESULT						Objects_Init();
void								Direct3D_Render( HWND hwnd);
void								Direct3D_Update( HWND hwnd);
void								Direct3D_CleanUp( );
float								Get_FPS();
void								Matrix_Set();


//-----------------------------------WinMain( )--------------------------------------
//	WindowsӦóںǵij↑ʼ
//------------------------------------------------------------------------------------------------
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nShowCmd)
{

	//1ڴIJ֮һʼһĴ
	WNDCLASSEX wndClass = { 0 };							//WINDCLASSEXһ
	wndClass.cbSize = sizeof( WNDCLASSEX ) ;			//ýṹֽС
	wndClass.style = CS_HREDRAW | CS_VREDRAW;	//ôڵʽ
	wndClass.lpfnWndProc = WndProc;					//ָ򴰿ڹָ̺
	wndClass.cbClsExtra		= 0;								//ĸڴ棬ȡ0Ϳ
	wndClass.cbWndExtra		= 0;							//ڵĸڴ棬Ȼȡ0
	wndClass.hInstance = hInstance;						//ָڹ̵ijʵ
	wndClass.hIcon=(HICON)::LoadImage(NULL,L"icon.ico",IMAGE_ICON,0,0,LR_DEFAULTSIZE|LR_LOADFROMFILE);  //ؼԶicoͼ
	wndClass.hCursor = LoadCursor( NULL, IDC_ARROW );    //ָĹ
	wndClass.hbrBackground=(HBRUSH)GetStockObject(GRAY_BRUSH);  //ΪhbrBackgroundԱָһɫˢ	
	wndClass.lpszMenuName = NULL;						//һԿַָֹ˵Դ֡
	wndClass.lpszClassName = L"ForTheDreamOfGameDevelop";		//һԿַָֹ֡

	//2ڴIJ֮עᴰ
	if( !RegisterClassEx( &wndClass ) )				//괰ںҪԴעᣬܴ͵Ĵ
		return -1;		

	//3ڴIJ֮ʽ
	HWND hwnd = CreateWindow( L"ForTheDreamOfGameDevelop",WINDOW_TITLE,				//ϲּĴںCreateWindow
		WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, WINDOW_WIDTH,
		WINDOW_HEIGHT, NULL, NULL, hInstance, NULL );

	//Direct3DԴijʼʧmessageboxʾ
	if (!(S_OK==Direct3D_Init (hwnd,hInstance)))
	{
		MessageBox(hwnd, _T("Direct3Dʼʧ~"), _T("dzīϢ"), 0); //ʹMessageBoxһϢ 
	}

	//4ڴIJ֮ģڵƶʾ
	MoveWindow(hwnd,250,80,WINDOW_WIDTH,WINDOW_HEIGHT,true);		//ʾʱλãʹϽλڣ250,80
	ShowWindow( hwnd, nShowCmd );    //ShowWindowʾ
	UpdateWindow(hwnd);						//Դڽи£·Ҫװһ

	//DirectInputijʼ
	g_pDInput = new DInputClass();
	g_pDInput->Init(hwnd,hInstance,DISCL_FOREGROUND | DISCL_NONEXCLUSIVE,DISCL_FOREGROUND | DISCL_NONEXCLUSIVE); //ǰ̨Ƕռģʽ
	PlaySound(L"쥹ˮ_.wav", NULL, SND_FILENAME | SND_ASYNC|SND_LOOP); //ѭű 

	//5Ϣѭ
	MSG msg = { 0 };  //ʼmsg
	while( msg.message != WM_QUIT )			//ʹwhileѭ
	{
		if( PeekMessage( &msg, 0, 0, 0, PM_REMOVE ) )   //鿴ӦóϢУϢʱеϢɷȥ
		{
			TranslateMessage( &msg );		//ϢתΪַϢ
			DispatchMessage( &msg );		//úַһϢڳ
		}
		else
		{
			Direct3D_Update(hwnd);			//øºлĸ
			Direct3D_Render(hwnd);			//ȾлȾ	
		}
	}
	//6ע
	UnregisterClass(L"ForTheDreamOfGameDevelop", wndClass.hInstance);  //׼ע
	return 0;  
}



//-----------------------------------WndProc( )--------------------------------------
//	ڹ̺WndProc,ԴϢд
//------------------------------------------------------------------------------------------------
LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )   //ڹ̺WndProc
{
	switch( message )				//switch俪ʼ
	{
	case WM_PAINT:					 // ͻػϢ
		Direct3D_Render(hwnd);          //Direct3D_RenderлĻ
		ValidateRect(hwnd, NULL);   // ¿ͻʾ
		break;									//switch

	case WM_KEYDOWN:                // ̰Ϣ
		if (wParam == VK_ESCAPE)    // ESC
			DestroyWindow(hwnd);    // ٴ, һWM_DESTROYϢ
		break;
	case WM_DESTROY:				//Ϣ
		Direct3D_CleanUp();     //Direct3D_CleanUpCOMӿڶ
		PostQuitMessage( 0 );		//ϵͳиֹ߳ӦWM_DESTROYϢ
		break;						//switch

	default:						//caseϣִиdefault
		return DefWindowProc( hwnd, message, wParam, lParam );		//ȱʡĴڹΪӦóûдĴϢṩȱʡĴ
	}

	return 0;					//˳
}


//-----------------------------------Direct3D_Init( )----------------------------------
//	Direct3DʼDirect3Dijʼ
//------------------------------------------------------------------------------------------------
HRESULT Direct3D_Init(HWND hwnd,HINSTANCE hInstance)
{

	//--------------------------------------------------------------------------------------
	// Direct3DʼIJ֮һӿڡDirect3Dӿڶ, ԱøDirect3D󴴽Direct3D豸
	//--------------------------------------------------------------------------------------
	LPDIRECT3D9  pD3D = NULL; //Direct3DӿڶĴ
	if( NULL == ( pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) ) //ʼDirect3Dӿڶ󣬲DirectX汾Э
		return E_FAIL;

	//--------------------------------------------------------------------------------------
	// Direct3DʼIJ֮,ȡϢȡӲ豸Ϣ
	//--------------------------------------------------------------------------------------
	D3DCAPS9 caps; int vp = 0;
	if( FAILED( pD3D->GetDeviceCaps( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &caps ) ) )
	{
		return E_FAIL;
	}
	if( caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT )
		vp = D3DCREATE_HARDWARE_VERTEXPROCESSING;   //֧Ӳ㣬ǾͲӲ㣬׵
	else
		vp = D3DCREATE_SOFTWARE_VERTEXPROCESSING; //֧Ӳ㣬ֻò

	//--------------------------------------------------------------------------------------
	// Direct3DʼIJ֮ݡD3DPRESENT_PARAMETERSṹ
	//--------------------------------------------------------------------------------------
	D3DPRESENT_PARAMETERS d3dpp; 
	ZeroMemory(&d3dpp, sizeof(d3dpp));
	d3dpp.BackBufferWidth            = WINDOW_WIDTH;
	d3dpp.BackBufferHeight           = WINDOW_HEIGHT;
	d3dpp.BackBufferFormat           = D3DFMT_A8R8G8B8;
	d3dpp.BackBufferCount            = 2;
	d3dpp.MultiSampleType            = D3DMULTISAMPLE_NONE;
	d3dpp.MultiSampleQuality         = 0;
	d3dpp.SwapEffect                 = D3DSWAPEFFECT_DISCARD; 
	d3dpp.hDeviceWindow              = hwnd;
	d3dpp.Windowed                   = true;
	d3dpp.EnableAutoDepthStencil     = true; 
	d3dpp.AutoDepthStencilFormat     = D3DFMT_D24S8;
	d3dpp.Flags                      = 0;
	d3dpp.FullScreen_RefreshRateInHz = 0;
	d3dpp.PresentationInterval       = D3DPRESENT_INTERVAL_IMMEDIATE;

	//--------------------------------------------------------------------------------------
	// Direct3DʼIJ֮ģ豸Direct3D豸ӿ
	//--------------------------------------------------------------------------------------
	if(FAILED(pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, 
		hwnd, vp, &d3dpp, &g_pd3dDevice)))
		return E_FAIL;


	//ȡԿϢg_strAdapterNameУԿ֮ǰϡǰԿͺţַ
	wchar_t TempName[60]=L"ǰԿͺţ";   //һʱַҷ˰"ǰԿͺţ"ַǵĿַ
	D3DADAPTER_IDENTIFIER9 Adapter;  //һD3DADAPTER_IDENTIFIER9ṹ壬ڴ洢ԿϢ
	pD3D->GetAdapterIdentifier(0,0,&Adapter);//GetAdapterIdentifierȡԿϢ
	int len = MultiByteToWideChar(CP_ACP,0, Adapter.Description, -1, NULL, 0);//ԿѾAdapter.DescriptionˣΪcharͣҪתΪwchar_t
	MultiByteToWideChar(CP_ACP, 0, Adapter.Description, -1, g_strAdapterName, len);//ⲽɺg_strAdapterNameоΪǰǵԿwchar_tַ
	wcscat_s(TempName,g_strAdapterName);//ѵǰǵԿӵǰԿͺţַ棬TempName
	wcscpy_s(g_strAdapterName,TempName);//TempNameеĽȫֱg_strAdapterNameУ󹦸~

	if(!(S_OK==Objects_Init())) return E_FAIL;

	SAFE_RELEASE(pD3D) //LPDIRECT3D9ӿڶʹɣǽͷŵ

		return S_OK;
}

//-----------------------------------Object_Init( )--------------------------------------
//	ȾԴʼڴ˺нҪȾԴijʼ
//--------------------------------------------------------------------------------------------------
HRESULT Objects_Init()
{
	//
	D3DXCreateFont(g_pd3dDevice, 36, 0, 0, 1000, false, DEFAULT_CHARSET, 
		OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, 0, _T("Calibri"), &g_pTextFPS);
	D3DXCreateFont(g_pd3dDevice, 20, 0, 1000, 0, false, DEFAULT_CHARSET, 
		OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, 0, L"", &g_pTextAdaperName); 
	D3DXCreateFont(g_pd3dDevice, 23, 0, 1000, 0, false, DEFAULT_CHARSET, 
		OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, 0, L"΢ź", &g_pTextHelper); 
	D3DXCreateFont(g_pd3dDevice, 26, 0, 1000, 0, false, DEFAULT_CHARSET, 
		OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, 0, L"", &g_pTextInfor); 

	//--------------------------------------------------------------------------------------
	// 㻺
	//--------------------------------------------------------------------------------------
	//㻺
	if( FAILED( g_pd3dDevice->CreateVertexBuffer( 24*sizeof(CUSTOMVERTEX),
		0, D3DFVF_CUSTOMVERTEX,
		D3DPOOL_DEFAULT, &g_pVertexBuffer, NULL ) ) )
	{
		return E_FAIL;
	}
	// 
	if( FAILED( 	g_pd3dDevice->CreateIndexBuffer(36* sizeof(WORD), 0, 
		D3DFMT_INDEX16, D3DPOOL_DEFAULT, &g_pIndexBuffer, NULL)) )
	{
		return E_FAIL;

	}
	//--------------------------------------------------------------------------------------
	// IJ֮ķ	
	//--------------------------------------------------------------------------------------
	//䶥㻺
	CUSTOMVERTEX* pVertices;
	if( FAILED( g_pVertexBuffer->Lock( 0, 24*sizeof(CUSTOMVERTEX), (void**)&pVertices, 0 ) ) )
		return E_FAIL;

	// 涥
	pVertices[0] = CUSTOMVERTEX(-10.0f,  10.0f, -10.0f, 0.0f, 0.0f);
	pVertices[1] = CUSTOMVERTEX( 10.0f,  10.0f, -10.0f, 1.0f, 0.0f);
	pVertices[2] = CUSTOMVERTEX( 10.0f, -10.0f, -10.0f, 1.0f, 1.0f);
	pVertices[3] = CUSTOMVERTEX(-10.0f, -10.0f, -10.0f, 0.0f, 1.0f);

	// 涥
	pVertices[4] = CUSTOMVERTEX( 10.0f,  10.0f, 10.0f, 0.0f, 0.0f);
	pVertices[5] = CUSTOMVERTEX(-10.0f,  10.0f, 10.0f, 1.0f, 0.0f);
	pVertices[6] = CUSTOMVERTEX(-10.0f, -10.0f, 10.0f, 1.0f, 1.0f);
	pVertices[7] = CUSTOMVERTEX( 10.0f, -10.0f, 10.0f, 0.0f, 1.0f);

	// 涥
	pVertices[8]  = CUSTOMVERTEX(-10.0f, 10.0f,  10.0f, 0.0f, 0.0f);
	pVertices[9]  = CUSTOMVERTEX( 10.0f, 10.0f,  10.0f, 1.0f, 0.0f);
	pVertices[10] = CUSTOMVERTEX( 10.0f, 10.0f, -10.0f, 1.0f, 1.0f);
	pVertices[11] = CUSTOMVERTEX(-10.0f, 10.0f, -10.0f, 0.0f, 1.0f);

	// 涥
	pVertices[12] = CUSTOMVERTEX(-10.0f, -10.0f, -10.0f, 0.0f, 0.0f);
	pVertices[13] = CUSTOMVERTEX( 10.0f, -10.0f, -10.0f, 1.0f, 0.0f);
	pVertices[14] = CUSTOMVERTEX( 10.0f, -10.0f,  10.0f, 1.0f, 1.0f);
	pVertices[15] = CUSTOMVERTEX(-10.0f, -10.0f,  10.0f, 0.0f, 1.0f);

	// 涥
	pVertices[16] = CUSTOMVERTEX(-10.0f,  10.0f,  10.0f, 0.0f, 0.0f);
	pVertices[17] = CUSTOMVERTEX(-10.0f,  10.0f, -10.0f, 1.0f, 0.0f);
	pVertices[18] = CUSTOMVERTEX(-10.0f, -10.0f, -10.0f, 1.0f, 1.0f);
	pVertices[19] = CUSTOMVERTEX(-10.0f, -10.0f,  10.0f, 0.0f, 1.0f);

	// Ҳ涥
	pVertices[20] = CUSTOMVERTEX( 10.0f,  10.0f, -10.0f, 0.0f, 0.0f);
	pVertices[21] = CUSTOMVERTEX( 10.0f,  10.0f,  10.0f, 1.0f, 0.0f);
	pVertices[22] = CUSTOMVERTEX( 10.0f, -10.0f,  10.0f, 1.0f, 1.0f);
	pVertices[23] = CUSTOMVERTEX( 10.0f, -10.0f, -10.0f, 0.0f, 1.0f);

	g_pVertexBuffer->Unlock();

	// 
	WORD *pIndices = NULL;
	g_pIndexBuffer->Lock(0, 0, (void**)&pIndices, 0);

	// 
	pIndices[0] = 0; pIndices[1] = 1; pIndices[2] = 2;
	pIndices[3] = 0; pIndices[4] = 2; pIndices[5] = 3;

	// 
	pIndices[6] = 4; pIndices[7]  = 5; pIndices[8]  = 6;
	pIndices[9] = 4; pIndices[10] = 6; pIndices[11] = 7;

	// 
	pIndices[12] = 8; pIndices[13] =  9; pIndices[14] = 10;
	pIndices[15] = 8; pIndices[16] = 10; pIndices[17] = 11;

	// 
	pIndices[18] = 12; pIndices[19] = 13; pIndices[20] = 14;
	pIndices[21] = 12; pIndices[22] = 14; pIndices[23] = 15;

	// 
	pIndices[24] = 16; pIndices[25] = 17; pIndices[26] = 18;
	pIndices[27] = 16; pIndices[28] = 18; pIndices[29] = 19;

	// Ҳ
	pIndices[30] = 20; pIndices[31] = 21; pIndices[32] = 22;
	pIndices[33] = 20; pIndices[34] = 22; pIndices[35] = 23;

	g_pIndexBuffer->Unlock();

	//--------------------------------------------------------------------------------------
	// IJ֮Ĵ
	//--------------------------------------------------------------------------------------
	D3DXCreateTextureFromFile(g_pd3dDevice, L"pal5q.jpg", &g_pTexture);

	// ò
	D3DMATERIAL9 mtrl;
	::ZeroMemory(&mtrl, sizeof(mtrl));
	mtrl.Ambient  = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	mtrl.Diffuse  = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	mtrl.Specular = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	g_pd3dDevice->SetMaterial(&mtrl);

	D3DLIGHT9 light;  
	::ZeroMemory(&light, sizeof(light));  
	light.Type          = D3DLIGHT_DIRECTIONAL;  
	light.Ambient       = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);  
	light.Diffuse       = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);  
	light.Specular      = D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f);  
	light.Direction     = D3DXVECTOR3(1.0f, 1.0f, 0.0f);  
	g_pd3dDevice->SetLight(0, &light); //ùԴ  
	g_pd3dDevice->LightEnable(0, true);//ù  

	// Ⱦ״̬
	g_pd3dDevice->SetRenderState(D3DRS_NORMALIZENORMALS, true);   //ʼ㷨
	g_pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);   //
	g_pd3dDevice->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_XRGB(36, 36, 36));   //һ» 

	return S_OK;
}

//-----------------------------------Matrix_Set( )--------------------------------------
//	װDirect3DĴ任ĺ任ȡ任ͶӰ任ӿڱ任
//--------------------------------------------------------------------------------------------------
void Matrix_Set()
{
	//--------------------------------------------------------------------------------------
	//Ĵ任֮һ任
	//--------------------------------------------------------------------------------------


	//--------------------------------------------------------------------------------------
	//Ĵ任֮ȡ任
	//--------------------------------------------------------------------------------------
	D3DXMATRIX matView; //һ
	D3DXVECTOR3 vEye(0.0f, 0.0f, -50.0f);  //λ
	D3DXVECTOR3 vAt(0.0f, 0.0f, 0.0f); //۲λ
	D3DXVECTOR3 vUp(0.0f, 1.0f, 0.0f);//ϵ
	D3DXMatrixLookAtLH(&matView, &vEye, &vAt, &vUp); //ȡ任
	g_pd3dDevice->SetTransform(D3DTS_VIEW, &matView); //Ӧȡ任

	//--------------------------------------------------------------------------------------
	//Ĵ任֮ͶӰ任
	//--------------------------------------------------------------------------------------
	D3DXMATRIX matProj; //һ
	D3DXMatrixPerspectiveFovLH(&matProj, D3DX_PI / 4.0f,(float)((double)WINDOW_WIDTH/WINDOW_HEIGHT),1.0f, 1000.0f); //ͶӰ任
	g_pd3dDevice->SetTransform(D3DTS_PROJECTION, &matProj);  //ͶӰ任

	//--------------------------------------------------------------------------------------
	//Ĵ任֮ġӿڱ任
	//--------------------------------------------------------------------------------------
	D3DVIEWPORT9 vp; //ʵһD3DVIEWPORT9ṹ壬ȻֵͿ
	vp.X      = 0;		//ʾӿڴڵX
	vp.Y      = 0;		//ӿԶԴڵY
	vp.Width  = WINDOW_WIDTH;	//ӿڵĿ
	vp.Height = WINDOW_HEIGHT; //ӿڵĸ߶
	vp.MinZ   = 0.0f; //ӿȻеСֵ
	vp.MaxZ   = 1.0f;	//ӿȻеֵ
	g_pd3dDevice->SetViewport(&vp); //ӿڵ

}


//-----------------------------------Direct3D_Update( )--------------------------------
//	ǼʱȾ뵫Ҫʱõģ簴ĸģ
//--------------------------------------------------------------------------------------------------
void				Direct3D_Update( HWND hwnd)
{
	//ʹDirectInputȡ
	g_pDInput->GetInput();

	// ȡϢӦģʽ
	if (g_pDInput->IsKeyDown(DIK_1))         // ּ1£ʵ
		g_pd3dDevice->SetRenderState(D3DRS_FILLMODE,D3DFILL_SOLID);		
	if (g_pDInput->IsKeyDown(DIK_2))         // ּ2£߿
		g_pd3dDevice->SetRenderState(D3DRS_FILLMODE,D3DFILL_WIREFRAME);

	// ס϶ΪƽƲ
	static FLOAT fPosX = 0.0f, fPosY = 0.0f, fPosZ = 0.0f;

	if (g_pDInput->IsMouseButtonDown(0)) 
	{
		fPosX += (g_pDInput->MouseDX())*  0.08f;
		fPosY += (g_pDInput->MouseDY()) * -0.08f;
	}

	//֣Ϊ۲
	fPosZ += (g_pDInput->MouseDZ())* 0.02f;

	// ƽ
	if (g_pDInput->IsKeyDown(DIK_A)) fPosX -= 0.005f;
	if (g_pDInput->IsKeyDown(DIK_D)) fPosX += 0.005f;
	if (g_pDInput->IsKeyDown(DIK_W)) fPosY += 0.005f;
	if (g_pDInput->IsKeyDown(DIK_S)) fPosY -= 0.005f;


	D3DXMatrixTranslation(&g_matWorld, fPosX, fPosY, fPosZ);


	// סҼ϶Ϊת
	static float fAngleX = D3DX_PI/6, fAngleY =D3DX_PI/6 ;

	if (g_pDInput->IsMouseButtonDown(1)) 
	{
		fAngleX += (g_pDInput->MouseDY())* -0.01f;
		fAngleY += (g_pDInput->MouseDX()) * -0.01f;
	}
	// ת
	if (g_pDInput->IsKeyDown(DIK_UP)) fAngleX += 0.005f;
	if (g_pDInput->IsKeyDown(DIK_DOWN)) fAngleX -= 0.005f;
	if (g_pDInput->IsKeyDown(DIK_LEFT)) fAngleY -= 0.005f;
	if (g_pDInput->IsKeyDown(DIK_RIGHT)) fAngleY += 0.005f;


	D3DXMATRIX Rx, Ry;
	D3DXMatrixRotationX(&Rx, fAngleX);
	D3DXMatrixRotationY(&Ry, fAngleY);

	g_matWorld = Rx * Ry * g_matWorld; //յ
	g_pd3dDevice->SetTransform(D3DTS_WORLD, &g_matWorld);//

	Matrix_Set();
}



//-----------------------------------Direct3D_Render( )-------------------------------
//	ʹDirect3DȾ
//--------------------------------------------------------------------------------------------------
void Direct3D_Render(HWND hwnd)
{

	//--------------------------------------------------------------------------------------
	// Direct3DȾ岽֮һ
	//--------------------------------------------------------------------------------------
	g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(100, 100, 100), 1.0f, 0);

	//һΣڻȡھ
	RECT formatRect;
	GetClientRect(hwnd, &formatRect);

	//--------------------------------------------------------------------------------------
	// Direct3DȾ岽֮ʼ
	//--------------------------------------------------------------------------------------
	g_pd3dDevice->BeginScene();                     // ʼ

	//--------------------------------------------------------------------------------------
	// Direct3DȾ岽֮ʽƣö㻺ͼ
	//--------------------------------------------------------------------------------------

	g_pd3dDevice->SetStreamSource( 0, g_pVertexBuffer, 0, sizeof(CUSTOMVERTEX) );//ѰļϢĶ㻺Ⱦˮ
	g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );//ָʹõʽĺ
	g_pd3dDevice->SetIndices(g_pIndexBuffer);//
	//--------------------------------------------------------------------------------------
	// IJ֮ġ
	//--------------------------------------------------------------------------------------
	g_pd3dDevice->SetTexture(0, g_pTexture);  //

	g_pd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 24, 0, 12);//϶㻺ͼ

	//ڴϽǴʾÿ֡
	int charCount = swprintf_s(g_strFPS, 20, _T("FPS:%0.3f"), Get_FPS() );
	g_pTextFPS->DrawText(NULL, g_strFPS, charCount , &formatRect, DT_TOP | DT_RIGHT, D3DCOLOR_RGBA(0,239,136,255));

	//ʾԿ
	g_pTextAdaperName->DrawText(NULL,g_strAdapterName, -1, &formatRect, 
		DT_TOP | DT_LEFT, D3DXCOLOR(1.0f, 0.5f, 0.0f, 1.0f));

	// Ϣ
	formatRect.top = 30;
	static wchar_t strInfo[256] = {0};
	swprintf_s(strInfo,-1, L"ģ: (%.2f, %.2f, %.2f)", g_matWorld._41, g_matWorld._42, g_matWorld._43);
	g_pTextHelper->DrawText(NULL, strInfo, -1, &formatRect, DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(135,239,136,255));

	// Ϣ
	formatRect.left = 0,formatRect.top = 380;
	g_pTextInfor->DrawText(NULL, L"˵:", -1, &formatRect, 
		DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(235,123,230,255));
	formatRect.top += 35;
	g_pTextHelper->DrawText(NULL, L"    ס϶ƽģ", -1, &formatRect, 
		DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(255,200,0,255));
	formatRect.top += 25;
	g_pTextHelper->DrawText(NULL, L"    סҼ϶תģ", -1, &formatRect, 
		DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(255,200,0,255));
	formatRect.top += 25;
	g_pTextHelper->DrawText(NULL, L"    ֣ģ", -1, &formatRect, 
		DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(255,200,0,255));
	formatRect.top += 25;
	g_pTextHelper->DrawText(NULL, L"    WSADƽģ ", -1, &formatRect, 
		DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(255,200,0,255));
	formatRect.top += 25;
	g_pTextHelper->DrawText(NULL, L"    ϡ¡ҷתģ ", -1, &formatRect, 
		DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(255,200,0,255));
	formatRect.top += 25;
	g_pTextHelper->DrawText(NULL, L"    1,2ּģʽ֮л ", -1, &formatRect, 
		DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(255,200,0,255));
	formatRect.top += 25;
	g_pTextHelper->DrawText(NULL, L"    ESC : ˳", -1, &formatRect, 
		DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(255,200,0,255));


	//--------------------------------------------------------------------------------------
	// Direct3DȾ岽֮ġ
	//--------------------------------------------------------------------------------------
	g_pd3dDevice->EndScene();                       // 
	//--------------------------------------------------------------------------------------
	// Direct3DȾ岽֮塿ʾת
	//--------------------------------------------------------------------------------------
	g_pd3dDevice->Present(NULL, NULL, NULL, NULL);  // תʾ

}



//-----------------------------------Get_FPS( )------------------------------------------
//	ڼÿ֡ʵһ
//--------------------------------------------------------------------------------------------------
float Get_FPS()
{

	//ĸ̬
	static float  fps = 0; //ҪFPSֵ
	static int    frameCount = 0;//֡
	static float  currentTime =0.0f;//ǰʱ
	static float  lastTime = 0.0f;//ʱ

	frameCount++;//ÿһGet_FPS()֡1
	currentTime = timeGetTime()*0.001f;//ȡϵͳʱ䣬timeGetTimeصԺΪλϵͳʱ䣬Ҫ0.001õλΪʱ

	//ǰʱȥʱ1ӣͽһFPSļͳʱĸ£ֵ֡
	if(currentTime - lastTime > 1.0f) //ʱ1
	{
		fps = (float)frameCount /(currentTime - lastTime);//1ӵFPSֵ
		lastTime = currentTime; //ǰʱcurrentTimeʱlastTimeΪһĻ׼ʱ
		frameCount    = 0;//֡frameCountֵ
	}

	return fps;
}



//-----------------------------------Direct3D_CleanUp( )--------------------------------
//	Direct3DԴͷCOMӿڶ
//---------------------------------------------------------------------------------------------------
void Direct3D_CleanUp()
{
	//ͷCOMӿڶ
	SAFE_DELETE(g_pDInput);
	SAFE_RELEASE(g_pVertexBuffer)
		SAFE_RELEASE(g_pIndexBuffer)
		SAFE_RELEASE(g_pTexture)
		SAFE_RELEASE(g_pTextAdaperName)
		SAFE_RELEASE(g_pTextHelper)
		SAFE_RELEASE(g_pTextInfor)
		SAFE_RELEASE(g_pTextFPS)
		SAFE_RELEASE(g_pd3dDevice)
}



================================================
FILE: Direct3D-Game-Demo/D3Ddemo10/DirectInputClass.cpp
================================================
//=============================================================================
// Desc: DirectInput봦Դļ
// 2013 203  Create by dzī 
//=============================================================================
#include "DirectInputClass.h"


//-----------------------------------------------------------------------------
// Desc: 캯
//-----------------------------------------------------------------------------
DInputClass::DInputClass()
{
	m_pDirectInput = NULL;
	m_KeyboardDevice = NULL;
	ZeroMemory(m_keyBuffer,sizeof(char)*256);
	m_MouseDevice= NULL;
	ZeroMemory(&m_MouseState, sizeof(m_MouseState));
}


//-----------------------------------------------------------------------------
// NameDInputClass::Init(
// Desc: ʼDirectInput̼豸
//-----------------------------------------------------------------------------
HRESULT DInputClass::Init( HWND hWnd,HINSTANCE hInstance,DWORD keyboardCoopFlags, DWORD mouseCoopFlags )
{
	HRESULT hr;
	//ʼһIDirectInput8ӿڶ
	HR(DirectInput8Create( hInstance, DIRECTINPUT_VERSION, 
		IID_IDirectInput8,(void**)&m_pDirectInput,NULL ));

	//м豸ijʼ
	HR( m_pDirectInput->CreateDevice( GUID_SysKeyboard, &m_KeyboardDevice, NULL ));
	HR( m_KeyboardDevice->SetCooperativeLevel( hWnd, keyboardCoopFlags));
	HR( m_KeyboardDevice->SetDataFormat( &c_dfDIKeyboard ));
	HR( m_KeyboardDevice->Acquire( ));
	HR( m_KeyboardDevice->Poll( ));

	//豸ijʼ
	HR( m_pDirectInput->CreateDevice( GUID_SysMouse, &m_MouseDevice, NULL ));
	HR( m_MouseDevice->SetCooperativeLevel( hWnd,mouseCoopFlags));
	HR( m_MouseDevice->SetDataFormat( &c_dfDIMouse ));
	HR( m_MouseDevice->Acquire( ));
	HR( m_KeyboardDevice->Poll( ));

	return S_OK;
}


//-----------------------------------------------------------------------------
// NameDInputClass::GetInput()
// Desc: ڻȡϢĺ
//-----------------------------------------------------------------------------
void DInputClass::GetInput()
{
	HRESULT hr = m_KeyboardDevice->GetDeviceState(sizeof(m_keyBuffer), (void**)&m_keyBuffer); 
	//ȡϢ
	if(hr)
	{
		m_KeyboardDevice->Acquire();  
		m_KeyboardDevice->GetDeviceState( sizeof(m_keyBuffer),(LPVOID)m_keyBuffer );
	}

	hr = m_MouseDevice->GetDeviceState(sizeof(DIMOUSESTATE), (void**)&m_MouseState); 
	//ȡϢ
	if(hr)
	{
		m_MouseDevice->Acquire();
		m_MouseDevice->GetDeviceState( sizeof(DIMOUSESTATE), (void**)&m_MouseState);
	}
}

//-----------------------------------------------------------------------------
// NameDInputClass::IsKeyDown()
// Desc: жϼijǷ
//-----------------------------------------------------------------------------
bool DInputClass::IsKeyDown(int iKey)
{
	if(m_keyBuffer[iKey] & 0x80)
		return true;
	else
		return false;
}


//-----------------------------------------------------------------------------
// NameDInputClass::IsMouseButtonDown()
// Desc: жijǷ
//-----------------------------------------------------------------------------
bool DInputClass::IsMouseButtonDown(int button)
{
	return (m_MouseState.rgbButtons[button] & 0x80) != 0;
}

//-----------------------------------------------------------------------------
// NameDInputClass::MouseDX
// Desc: ָXֵ
//-----------------------------------------------------------------------------
float DInputClass::MouseDX()
{
	return (float)m_MouseState.lX;
}

//-----------------------------------------------------------------------------
// NameDInputClass::MouseDY
// Desc: ָYֵ
//-----------------------------------------------------------------------------
float DInputClass::MouseDY()
{
	return (float)m_MouseState.lY;
}

//-----------------------------------------------------------------------------
// NameDInputClass::MouseDZ
// Desc: ָZֵ֣
//-----------------------------------------------------------------------------
float DInputClass::MouseDZ()
{
	return (float)m_MouseState.lZ;
}




//-----------------------------------------------------------------------------
// Desc: 
//-----------------------------------------------------------------------------
DInputClass::~DInputClass(void)
{
	if(m_KeyboardDevice != NULL)
		m_KeyboardDevice->Unacquire();
	if(m_MouseDevice != NULL)
		m_MouseDevice->Unacquire();
	SAFE_RELEASE(m_KeyboardDevice);
	SAFE_RELEASE(m_MouseDevice);
	SAFE_RELEASE(m_pDirectInput);
}


================================================
FILE: Direct3D-Game-Demo/D3Ddemo10/DirectInputClass.h
================================================
//=============================================================================
// Name: DirectInputClass.h
//	Des: װDirectInput봦ͷļ
// 2013 203  Create by dzī 
//=============================================================================
#pragma once
#include "D3DUtil.h"
#define DIRECTINPUT_VERSION 0x0800
#include <dinput.h>

//DInputClassඨ忪ʼ
class DInputClass
{
private:
	IDirectInput8					* m_pDirectInput;   //IDirectInput8ӿڶ
	IDirectInputDevice8		* m_KeyboardDevice;  //豸ӿڶ
	char								m_keyBuffer[256];       //ڼֵ̼洢

	IDirectInputDevice8		*m_MouseDevice;      //豸ӿڶ
	DIMOUSESTATE				m_MouseState;			//ֵ洢һṹ

public:
	HRESULT		Init( HWND hWnd,HINSTANCE hInstance,DWORD keyboardCoopFlags, DWORD mouseCoopFlags ); //ʼDirectInput̼豸
	void				GetInput();   //ڻȡϢĺ
	bool				IsKeyDown(int iKey);   //жϼijǷ
	
	bool				IsMouseButtonDown(int button);  //ж갴Ƿ񱻰
	float				MouseDX();   //Xֵ
	float				MouseDY();	//Yֵ
	float				MouseDZ();	//Zֵ


public:
	DInputClass(void);		//캯
	~DInputClass(void);	//
};


================================================
FILE: Direct3D-Game-Demo/D3Ddemo11/D3DUtil.h
================================================

//=============================================================================
// Desc: D3DUtil.hͷļڹĶ
// 2013 203  Create by dzī 
//=============================================================================

#pragma once


#ifndef HR
#define HR(x)    { hr = x; if( FAILED(hr) ) { return hr; } }         //ԶһHRִ꣬дķ
#endif

#ifndef SAFE_DELETE					
#define SAFE_DELETE(p)       { if(p) { delete (p);     (p)=NULL; } }       //ԶһSAFE_RELEASE(),ָԴͷ
#endif    

#ifndef SAFE_RELEASE			
#define SAFE_RELEASE(p)      { if(p) { (p)->Release(); (p)=NULL; } }     //ԶһSAFE_RELEASE(),COMԴͷ
#endif

================================================
FILE: Direct3D-Game-Demo/D3Ddemo11/D3Ddemo11.cpp
================================================
//-----------------------------------˵----------------------------------------------
//  :D3Ddemo10
//	 20134 Create by dzī
//  Ϊάʣӳ ʾ֮
//  ͼ꼰ͼƬزģ ɽǰ 
//------------------------------------------------------------------------------------------------


//-----------------------------------궨岿֡--------------------------------------------
// һЩ
//------------------------------------------------------------------------------------------------
#define WINDOW_WIDTH	800						//Ϊڿȶĺ꣬Էڴ˴޸Ĵڿ
#define WINDOW_HEIGHT	600							//Ϊڸ߶ȶĺ꣬Էڴ˴޸Ĵڸ߶
#define WINDOW_TITLE	_T("ϨϷ롿Ϊάʣӳ ʾ֮") //Ϊڱⶨĺ



//-----------------------------------ͷļ֡---------------------------------------
//	ͷļ
//------------------------------------------------------------------------------------------------                                                                                     
#include <d3d9.h>
#include <d3dx9.h>
#include <tchar.h>
#include <time.h> 
#include "DirectInputClass.h"



//-----------------------------------ļ֡---------------------------------------
//	Ŀļ
//------------------------------------------------------------------------------------------------
#pragma comment(lib,"d3d9.lib")
#pragma comment(lib,"d3dx9.lib")
#pragma comment(lib, "dinput8.lib")     // ʹDirectInputͷļע8
#pragma comment(lib,"dxguid.lib")
#pragma comment(lib, "winmm.lib") 


//--------------------------------------------------------------------------------------
// IJ֮һĶ	
//--------------------------------------------------------------------------------------
struct CUSTOMVERTEX 
{
	FLOAT _x, _y, _z;               // λ
	FLOAT _u, _v;                   // 
	CUSTOMVERTEX(FLOAT x, FLOAT y, FLOAT z, FLOAT u, FLOAT v)
		: _x(x), _y(y), _z(z), _u(u), _v(v) {}
};
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ | D3DFVF_TEX1)

//-----------------------------------ȫֱ֡-------------------------------------
//	ȫֱ
//------------------------------------------------------------------------------------------------
LPDIRECT3DDEVICE9					g_pd3dDevice = NULL; //Direct3D豸
LPD3DXFONT								g_pTextFPS				=NULL;    //COMӿ
LPD3DXFONT								g_pTextAdaperName           = NULL;  // ԿϢ2Dı
LPD3DXFONT								g_pTextHelper          = NULL;  // Ϣ2Dı
LPD3DXFONT								g_pTextInfor           = NULL;  // Ϣ2Dı
float											g_FPS								= 0.0f;       //һ͵ı֡
wchar_t										g_strFPS[50]={0};    //֡ʵַ
wchar_t										g_strAdapterName[60]={0};    //ԿƵַ
D3DXMATRIX							g_matWorld;   //
LPDIRECT3DVERTEXBUFFER9		g_pVertexBuffer = NULL;    //㻺
LPDIRECT3DINDEXBUFFER9		g_pIndexBuffer  = NULL;    // 
LPDIRECT3DTEXTURE9				g_pMipTexture= NULL;    // ӿڶڽĴ
DInputClass*								g_pDInput = NULL;         //һDInputClassָ

//-----------------------------------ȫֺ֡-------------------------------------
//	ȫֺֹδıʶϵд
//------------------------------------------------------------------------------------------------
LRESULT CALLBACK		WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam );
HRESULT						Direct3D_Init(HWND hwnd,HINSTANCE hInstance);
HRESULT						Objects_Init();
void								Direct3D_Render( HWND hwnd);
void								Direct3D_Update( HWND hwnd);
void								Direct3D_CleanUp( );
float								Get_FPS();
void								Matrix_Set();


//-----------------------------------WinMain( )--------------------------------------
//	WindowsӦóںǵij↑ʼ
//------------------------------------------------------------------------------------------------
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nShowCmd)
{

	//1ڴIJ֮һʼһĴ
	WNDCLASSEX wndClass = { 0 };							//WINDCLASSEXһ
	wndClass.cbSize = sizeof( WNDCLASSEX ) ;			//ýṹֽС
	wndClass.style = CS_HREDRAW | CS_VREDRAW;	//ôڵʽ
	wndClass.lpfnWndProc = WndProc;					//ָ򴰿ڹָ̺
	wndClass.cbClsExtra		= 0;								//ĸڴ棬ȡ0Ϳ
	wndClass.cbWndExtra		= 0;							//ڵĸڴ棬Ȼȡ0
	wndClass.hInstance = hInstance;						//ָڹ̵ijʵ
	wndClass.hIcon=(HICON)::LoadImage(NULL,L"icon.ico",IMAGE_ICON,0,0,LR_DEFAULTSIZE|LR_LOADFROMFILE);  //ؼԶicoͼ
	wndClass.hCursor = LoadCursor( NULL, IDC_ARROW );    //ָĹ
	wndClass.hbrBackground=(HBRUSH)GetStockObject(GRAY_BRUSH);  //ΪhbrBackgroundԱָһɫˢ	
	wndClass.lpszMenuName = NULL;						//һԿַָֹ˵Դ֡
	wndClass.lpszClassName = L"ForTheDreamOfGameDevelop";		//һԿַָֹ֡

	//2ڴIJ֮עᴰ
	if( !RegisterClassEx( &wndClass ) )				//괰ںҪԴעᣬܴ͵Ĵ
		return -1;		

	//3ڴIJ֮ʽ
	HWND hwnd = CreateWindow( L"ForTheDreamOfGameDevelop",WINDOW_TITLE,				//ϲּĴںCreateWindow
		WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, WINDOW_WIDTH,
		WINDOW_HEIGHT, NULL, NULL, hInstance, NULL );

	//Direct3DԴijʼʧmessageboxʾ
	if (!(S_OK==Direct3D_Init (hwnd,hInstance)))
	{
		MessageBox(hwnd, _T("Direct3Dʼʧ~"), _T("dzīϢ"), 0); //ʹMessageBoxһϢ 
	}

	//4ڴIJ֮ģڵƶʾ
	MoveWindow(hwnd,250,80,WINDOW_WIDTH,WINDOW_HEIGHT,true);		//ʾʱλãʹϽλڣ250,80
	ShowWindow( hwnd, nShowCmd );    //ShowWindowʾ
	UpdateWindow(hwnd);						//Դڽи£·Ҫװһ

	//DirectInputijʼ
	g_pDInput = new DInputClass();
	g_pDInput->Init(hwnd,hInstance,DISCL_FOREGROUND | DISCL_NONEXCLUSIVE,DISCL_FOREGROUND | DISCL_NONEXCLUSIVE); //ǰ̨Ƕռģʽ
	PlaySound(L"ɽ̵깺.wav", NULL, SND_FILENAME | SND_ASYNC|SND_LOOP); //ѭű 

	//5Ϣѭ
	MSG msg = { 0 };  //ʼmsg
	while( msg.message != WM_QUIT )			//ʹwhileѭ
	{
		if( PeekMessage( &msg, 0, 0, 0, PM_REMOVE ) )   //鿴ӦóϢУϢʱеϢɷȥ
		{
			TranslateMessage( &msg );		//ϢתΪַϢ
			DispatchMessage( &msg );		//úַһϢڳ
		}
		else
		{
			Direct3D_Update(hwnd);			//øºлĸ
			Direct3D_Render(hwnd);			//ȾлȾ	
		}
	}
	//6ע
	UnregisterClass(L"ForTheDreamOfGameDevelop", wndClass.hInstance);  //׼ע
	return 0;  
	return 0;  
}



//-----------------------------------WndProc( )--------------------------------------
//	ڹ̺WndProc,ԴϢд
//------------------------------------------------------------------------------------------------
LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )   //ڹ̺WndProc
{
	switch( message )				//switch俪ʼ
	{
	case WM_PAINT:					 // ͻػϢ
		Direct3D_Render(hwnd);          //Direct3D_RenderлĻ
		ValidateRect(hwnd, NULL);   // ¿ͻʾ
		break;									//switch

	case WM_KEYDOWN:                // ̰Ϣ
		if (wParam == VK_ESCAPE)    // ESC
			DestroyWindow(hwnd);    // ٴ, һWM_DESTROYϢ
		break;
	case WM_DESTROY:				//Ϣ
		Direct3D_CleanUp();     //Direct3D_CleanUpCOMӿڶ
		PostQuitMessage( 0 );		//ϵͳиֹ߳ӦWM_DESTROYϢ
		break;						//switch

	default:						//caseϣִиdefault
		return DefWindowProc( hwnd, message, wParam, lParam );		//ȱʡĴڹΪӦóûдĴϢṩȱʡĴ
	}

	return 0;					//˳
}


//-----------------------------------Direct3D_Init( )----------------------------------
//	Direct3DʼDirect3Dijʼ
//------------------------------------------------------------------------------------------------
HRESULT Direct3D_Init(HWND hwnd,HINSTANCE hInstance)
{

	//--------------------------------------------------------------------------------------
	// Direct3DʼIJ֮һӿڡDirect3Dӿڶ, ԱøDirect3D󴴽Direct3D豸
	//--------------------------------------------------------------------------------------
	LPDIRECT3D9  pD3D = NULL; //Direct3DӿڶĴ
	if( NULL == ( pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) ) //ʼDirect3Dӿڶ󣬲DirectX汾Э
		return E_FAIL;

	//--------------------------------------------------------------------------------------
	// Direct3DʼIJ֮,ȡϢȡӲ豸Ϣ
	//--------------------------------------------------------------------------------------
	D3DCAPS9 caps; int vp = 0;
	if( FAILED( pD3D->GetDeviceCaps( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &caps ) ) )
	{
		return E_FAIL;
	}
	if( caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT )
		vp = D3DCREATE_HARDWARE_VERTEXPROCESSING;   //֧Ӳ㣬ǾͲӲ㣬׵
	else
		vp = D3DCREATE_SOFTWARE_VERTEXPROCESSING; //֧Ӳ㣬ֻò

	//--------------------------------------------------------------------------------------
	// Direct3DʼIJ֮ݡD3DPRESENT_PARAMETERSṹ
	//--------------------------------------------------------------------------------------
	D3DPRESENT_PARAMETERS d3dpp; 
	ZeroMemory(&d3dpp, sizeof(d3dpp));
	d3dpp.BackBufferWidth            = WINDOW_WIDTH;
	d3dpp.BackBufferHeight           = WINDOW_HEIGHT;
	d3dpp.BackBufferFormat           = D3DFMT_A8R8G8B8;
	d3dpp.BackBufferCount            = 2;
	d3dpp.MultiSampleType            = D3DMULTISAMPLE_NONE;
	d3dpp.MultiSampleQuality         = 0;
	d3dpp.SwapEffect                 = D3DSWAPEFFECT_DISCARD; 
	d3dpp.hDeviceWindow              = hwnd;
	d3dpp.Windowed                   = true;
	d3dpp.EnableAutoDepthStencil     = true; 
	d3dpp.AutoDepthStencilFormat     = D3DFMT_D24S8;
	d3dpp.Flags                      = 0;
	d3dpp.FullScreen_RefreshRateInHz = 0;
	d3dpp.PresentationInterval       = D3DPRESENT_INTERVAL_IMMEDIATE;

	//--------------------------------------------------------------------------------------
	// Direct3DʼIJ֮ģ豸Direct3D豸ӿ
	//--------------------------------------------------------------------------------------
	if(FAILED(pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, 
		hwnd, vp, &d3dpp, &g_pd3dDevice)))
		return E_FAIL;


	//ȡԿϢg_strAdapterNameУԿ֮ǰϡǰԿͺţַ
	wchar_t TempName[60]=L"ǰԿͺţ";   //һʱַҷ˰"ǰԿͺţ"ַǵĿַ
	D3DADAPTER_IDENTIFIER9 Adapter;  //һD3DADAPTER_IDENTIFIER9ṹ壬ڴ洢ԿϢ
	pD3D->GetAdapterIdentifier(0,0,&Adapter);//GetAdapterIdentifierȡԿϢ
	int len = MultiByteToWideChar(CP_ACP,0, Adapter.Description, -1, NULL, 0);//ԿѾAdapter.DescriptionˣΪcharͣҪתΪwchar_t
	MultiByteToWideChar(CP_ACP, 0, Adapter.Description, -1, g_strAdapterName, len);//ⲽɺg_strAdapterNameоΪǰǵԿwchar_tַ
	wcscat_s(TempName,g_strAdapterName);//ѵǰǵԿӵǰԿͺţַ棬TempName
	wcscpy_s(g_strAdapterName,TempName);//TempNameеĽȫֱg_strAdapterNameУ󹦸~

	if(!(S_OK==Objects_Init())) return E_FAIL;

	SAFE_RELEASE(pD3D) //LPDIRECT3D9ӿڶʹɣǽͷŵ

		return S_OK;
}

//-----------------------------------Object_Init( )--------------------------------------
//	ȾԴʼڴ˺нҪȾԴijʼ
//--------------------------------------------------------------------------------------------------
HRESULT Objects_Init()
{
	//
	D3DXCreateFont(g_pd3dDevice, 36, 0, 0, 1000, false, DEFAULT_CHARSET, 
		OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, 0, _T("Calibri"), &g_pTextFPS);
	D3DXCreateFont(g_pd3dDevice, 20, 0, 1000, 0, false, DEFAULT_CHARSET, 
		OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, 0, L"", &g_pTextAdaperName); 
	D3DXCreateFont(g_pd3dDevice, 23, 0, 1000, 0, false, DEFAULT_CHARSET, 
		OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, 0, L"΢ź", &g_pTextHelper); 
	D3DXCreateFont(g_pd3dDevice, 26, 0, 1000, 0, false, DEFAULT_CHARSET, 
		OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, 0, L"", &g_pTextInfor); 

	//--------------------------------------------------------------------------------------
	// 㻺桢ͼIJ֮㻺
	//--------------------------------------------------------------------------------------
	//㻺
	if( FAILED( g_pd3dDevice->CreateVertexBuffer( 24*sizeof(CUSTOMVERTEX),
		0, D3DFVF_CUSTOMVERTEX,
		D3DPOOL_DEFAULT, &g_pVertexBuffer, NULL ) ) )
	{
		return E_FAIL;
	}
	// 
	if( FAILED( 	g_pd3dDevice->CreateIndexBuffer(36* sizeof(WORD), 0, 
		D3DFMT_INDEX16, D3DPOOL_DEFAULT, &g_pIndexBuffer, NULL)) )
	{
		return E_FAIL;

	}
	//--------------------------------------------------------------------------------------
	// 㻺桢ͼIJ֮ʶ㻺
	//--------------------------------------------------------------------------------------
	//--------------------------------------------------------------------------------------
	// IJ֮ķ	
	//--------------------------------------------------------------------------------------
	//䶥㻺
	CUSTOMVERTEX* pVertices;
	if( FAILED( g_pVertexBuffer->Lock( 0, sizeof(CUSTOMVERTEX), (void**)&pVertices, 0 ) ) )
		return E_FAIL;

	// 涥
	pVertices[0] = CUSTOMVERTEX(-10.0f,  10.0f, -10.0f, 0.0f, 0.0f);
	pVertices[1] = CUSTOMVERTEX( 10.0f,  10.0f, -10.0f, 2.0f, 0.0f);
	pVertices[2] = CUSTOMVERTEX( 10.0f, -10.0f, -10.0f, 2.0f, 2.0f);
	pVertices[3] = CUSTOMVERTEX(-10.0f, -10.0f, -10.0f, 0.0f, 2.0f);

	// 涥
	pVertices[4] = CUSTOMVERTEX( 10.0f,  10.0f, 10.0f, 0.0f, 0.0f);
	pVertices[5] = CUSTOMVERTEX(-10.0f,  10.0f, 10.0f, 2.0f, 0.0f);
	pVertices[6] = CUSTOMVERTEX(-10.0f, -10.0f, 10.0f, 2.0f, 2.0f);
	pVertices[7] = CUSTOMVERTEX( 10.0f, -10.0f, 10.0f, 0.0f, 2.0f);

	// 涥
	pVertices[8]  = CUSTOMVERTEX(-10.0f, 10.0f,  10.0f, 0.0f, 0.0f);
	pVertices[9]  = CUSTOMVERTEX( 10.0f, 10.0f,  10.0f, 2.0f, 0.0f);
	pVertices[10] = CUSTOMVERTEX( 10.0f, 10.0f, -10.0f, 2.0f, 2.0f);
	pVertices[11] = CUSTOMVERTEX(-10.0f, 10.0f, -10.0f, 0.0f, 2.0f);

	// 涥
	pVertices[12] = CUSTOMVERTEX(-10.0f, -10.0f, -10.0f, 0.0f, 0.0f);
	pVertices[13] = CUSTOMVERTEX( 10.0f, -10.0f, -10.0f, 2.0f, 0.0f);
	pVertices[14] = CUSTOMVERTEX( 10.0f, -10.0f,  10.0f, 2.0f, 2.0f);
	pVertices[15] = CUSTOMVERTEX(-10.0f, -10.0f,  10.0f, 0.0f, 2.0f);

	// 涥
	pVertices[16] = CUSTOMVERTEX(-10.0f,  10.0f,  10.0f, 0.0f, 0.0f);
	pVertices[17] = CUSTOMVERTEX(-10.0f,  10.0f, -10.0f, 1.0f, 0.0f);
	pVertices[18] = CUSTOMVERTEX(-10.0f, -10.0f, -10.0f, 1.0f, 1.0f);
	pVertices[19] = CUSTOMVERTEX(-10.0f, -10.0f,  10.0f, 0.0f, 1.0f);

	// Ҳ涥
	pVertices[20] = CUSTOMVERTEX( 10.0f,  10.0f, -10.0f, 0.0f, 0.0f);
	pVertices[21] = CUSTOMVERTEX( 10.0f,  10.0f,  10.0f, 1.0f, 0.0f);
	pVertices[22] = CUSTOMVERTEX( 10.0f, -10.0f,  10.0f, 1.0f, 1.0f);
	pVertices[23] = CUSTOMVERTEX( 10.0f, -10.0f, -10.0f, 0.0f, 1.0f);

	g_pVertexBuffer->Unlock();

	// 
	WORD *pIndices = NULL;
	g_pIndexBuffer->Lock(0, 0, (void**)&pIndices, 0);

	// 
	pIndices[0] = 0; pIndices[1] = 1; pIndices[2] = 2;
	pIndices[3] = 0; pIndices[4] = 2; pIndices[5] = 3;

	// 
	pIndices[6] = 4; pIndices[7]  = 5; pIndices[8]  = 6;
	pIndices[9] = 4; pIndices[10] = 6; pIndices[11] = 7;

	// 
	pIndices[12] = 8; pIndices[13] =  9; pIndices[14] = 10;
	pIndices[15] = 8; pIndices[16] = 10; pIndices[17] = 11;

	// 
	pIndices[18] = 12; pIndices[19] = 13; pIndices[20] = 14;
	pIndices[21] = 12; pIndices[22] = 14; pIndices[23] = 15;

	// 
	pIndices[24] = 16; pIndices[25] = 17; pIndices[26] = 18;
	pIndices[27] = 16; pIndices[28] = 18; pIndices[29] = 19;

	// Ҳ
	pIndices[30] = 20; pIndices[31] = 21; pIndices[32] = 22;
	pIndices[33] = 20; pIndices[34] = 22; pIndices[35] = 23;

	g_pIndexBuffer->Unlock();

	//--------------------------------------------------------------------------------------
	// IJ֮Ĵ
	//--------------------------------------------------------------------------------------
	// 
	D3DXCreateTextureFromFileEx(g_pd3dDevice, L"pal5q.jpg", 0, 0, 6, 0, D3DFMT_X8R8G8B8, 
		D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0xFF000000, 0, 0, &g_pMipTexture);

	// ò
	D3DMATERIAL9 mtrl;
	::ZeroMemory(&mtrl, sizeof(mtrl));
	mtrl.Ambient  = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	mtrl.Diffuse  = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	mtrl.Specular = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	g_pd3dDevice->SetMaterial(&mtrl);

	// ʼȾ״̬
	g_pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);   //
	g_pd3dDevice->SetRenderState(D3DRS_AMBIENT, D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f)); //û

	//Թ
	g_pd3dDevice->SetSamplerState(0, D3DSAMP_MAXANISOTROPY, 3);
	g_pd3dDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_ANISOTROPIC);
	g_pd3dDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_ANISOTROPIC);

	//
	//		g_pd3dDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
	//	 	g_pd3dDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);

	// 
	// 		g_pd3dDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
	// 		g_pd3dDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT);

	// 
	// 		g_pd3dDevice->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);
	// 		g_pd3dDevice->SetSamplerState(0, D3DSAMP_MAXMIPLEVEL, 16);
	return S_OK;
}

//-----------------------------------Matrix_Set( )--------------------------------------
//	װDirect3DĴ任ĺ任ȡ任ͶӰ任ӿڱ任
//--------------------------------------------------------------------------------------------------
void Matrix_Set()
{
	//--------------------------------------------------------------------------------------
	//Ĵ任֮һ任
	//--------------------------------------------------------------------------------------


	//--------------------------------------------------------------------------------------
	//Ĵ任֮ȡ任
	//--------------------------------------------------------------------------------------
	D3DXMATRIX matView; //һ
	D3DXVECTOR3 vEye(0.0f, 0.0f, -50.0f);  //λ
	D3DXVECTOR3 vAt(0.0f, 0.0f, 0.0f); //۲λ
	D3DXVECTOR3 vUp(0.0f, 1.0f, 0.0f);//ϵ
	D3DXMatrixLookAtLH(&matView, &vEye, &vAt, &vUp); //ȡ任
	g_pd3dDevice->SetTransform(D3DTS_VIEW, &matView); //Ӧȡ任

	//--------------------------------------------------------------------------------------
	//Ĵ任֮ͶӰ任
	//--------------------------------------------------------------------------------------
	D3DXMATRIX matProj; //һ
	D3DXMatrixPerspectiveFovLH(&matProj, D3DX_PI / 4.0f,(float)((double)WINDOW_WIDTH/WINDOW_HEIGHT),1.0f, 1000.0f); //ͶӰ任
	g_pd3dDevice->SetTransform(D3DTS_PROJECTION, &matProj);  //ͶӰ任

	//--------------------------------------------------------------------------------------
	//Ĵ任֮ġӿڱ任
	//--------------------------------------------------------------------------------------
	D3DVIEWPORT9 vp; //ʵһD3DVIEWPORT9ṹ壬ȻֵͿ
	vp.X      = 0;		//ʾӿڴڵX
	vp.Y      = 0;		//ӿԶԴڵY
	vp.Width  = WINDOW_WIDTH;	//ӿڵĿ
	vp.Height = WINDOW_HEIGHT; //ӿڵĸ߶
	vp.MinZ   = 0.0f; //ӿȻеСֵ
	vp.MaxZ   = 1.0f;	//ӿȻеֵ
	g_pd3dDevice->SetViewport(&vp); //ӿڵ

}


//-----------------------------------Direct3D_Update( )--------------------------------
//	ǼʱȾ뵫Ҫʱõģ簴ĸģ
//--------------------------------------------------------------------------------------------------
void				Direct3D_Update( HWND hwnd)
{
	//ʹDirectInputȡ
	g_pDInput->GetInput();


	// ݼ̰İ£ΪѰַʽ
	if (g_pDInput->IsKeyDown(DIK_1))  //1
	{
		// ظѰַģʽ
		g_pd3dDevice->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
		g_pd3dDevice->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);
	}
	if (g_pDInput->IsKeyDown(DIK_2)) //2
	{
		// þѰַģʽ
		g_pd3dDevice->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_MIRROR);
		g_pd3dDevice->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_MIRROR);
	}
	if (g_pDInput->IsKeyDown(DIK_3)) //3
	{
		// üȡѰַģʽ
		g_pd3dDevice->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
		g_pd3dDevice->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
	}
	if (g_pDInput->IsKeyDown(DIK_4)) //4
	{
		// ñ߿Ѱַģʽ
		g_pd3dDevice->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER);
		g_pd3dDevice->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER);
	}

	// ס϶ΪƽƲ
	static FLOAT fPosX = 0.0f, fPosY = 0.0f, fPosZ = 0.0f;

	if (g_pDInput->IsMouseButtonDown(0)) 
	{
		fPosX += (g_pDInput->MouseDX())*  0.08f;
		fPosY += (g_pDInput->MouseDY()) * -0.08f;
	}

	//֣Ϊ۲
	fPosZ += (g_pDInput->MouseDZ())* 0.02f;

	// ƽ
	if (g_pDInput->IsKeyDown(DIK_A)) fPosX -= 0.005f;
	if (g_pDInput->IsKeyDown(DIK_D)) fPosX += 0.005f;
	if (g_pDInput->IsKeyDown(DIK_W)) fPosY += 0.005f;
	if (g_pDInput->IsKeyDown(DIK_S)) fPosY -= 0.005f;


	D3DXMatrixTranslation(&g_matWorld, fPosX, fPosY, fPosZ);


	// סҼ϶Ϊת
	static float fAngleX = D3DX_PI/6, fAngleY =D3DX_PI/6 ;

	if (g_pDInput->IsMouseButtonDown(1)) 
	{
		fAngleX += (g_pDInput->MouseDY())* -0.01f;
		fAngleY += (g_pDInput->MouseDX()) * -0.01f;
	}
	// ת
	if (g_pDInput->IsKeyDown(DIK_UP)) fAngleX += 0.005f;
	if (g_pDInput->IsKeyDown(DIK_DOWN)) fAngleX -= 0.005f;
	if (g_pDInput->IsKeyDown(DIK_LEFT)) fAngleY -= 0.005f;
	if (g_pDInput->IsKeyDown(DIK_RIGHT)) fAngleY += 0.005f;


	D3DXMATRIX Rx, Ry;
	D3DXMatrixRotationX(&Rx, fAngleX);
	D3DXMatrixRotationY(&Ry, fAngleY);

	g_matWorld = Rx * Ry * g_matWorld; //յ
	g_pd3dDevice->SetTransform(D3DTS_WORLD, &g_matWorld);//
	Matrix_Set();
}



//-----------------------------------Direct3D_Render( )-------------------------------
//	ʹDirect3DȾ
//--------------------------------------------------------------------------------------------------
void Direct3D_Render(HWND hwnd)
{

	//--------------------------------------------------------------------------------------
	// Direct3DȾ岽֮һ
	//--------------------------------------------------------------------------------------
	g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(100, 100, 100), 1.0f, 0);

	//һΣڻȡھ
	RECT formatRect;
	GetClientRect(hwnd, &formatRect);

	//--------------------------------------------------------------------------------------
	// Direct3DȾ岽֮ʼ
	//--------------------------------------------------------------------------------------
	g_pd3dDevice->BeginScene();                     // ʼ

	//--------------------------------------------------------------------------------------
	// Direct3DȾ岽֮ʽƣö㻺ͼ
	//--------------------------------------------------------------------------------------

	g_pd3dDevice->SetStreamSource( 0, g_pVertexBuffer, 0, sizeof(CUSTOMVERTEX) );//ѰļϢĶ㻺Ⱦˮ
	g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );//ָʹõʽĺ
	g_pd3dDevice->SetIndices(g_pIndexBuffer);//
	//--------------------------------------------------------------------------------------
	// IJ֮ġ
	//--------------------------------------------------------------------------------------
	g_pd3dDevice->SetTexture(0, g_pMipTexture);  //

	g_pd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 24, 0, 12);//϶㻺ͼ

	//ڴϽǴʾÿ֡
	int charCount = swprintf_s(g_strFPS, 20, _T("FPS:%0.3f"), Get_FPS() );
	g_pTextFPS->DrawText(NULL, g_strFPS, charCount , &formatRect, DT_TOP | DT_RIGHT, D3DCOLOR_RGBA(0,239,136,255));

	//ʾԿ
	g_pTextAdaperName->DrawText(NULL,g_strAdapterName, -1, &formatRect, 
		DT_TOP | DT_LEFT, D3DXCOLOR(1.0f, 0.5f, 0.0f, 1.0f));

	// Ϣ
	formatRect.top = 30;
	static wchar_t strInfo[256] = {0};
	swprintf_s(strInfo,-1, L"ģ: (%.2f, %.2f, %.2f)", g_matWorld._41, g_matWorld._42, g_matWorld._43);
	g_pTextHelper->DrawText(NULL, strInfo, -1, &formatRect, DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(135,239,136,255));

	// Ϣ
	formatRect.left = 0,formatRect.top = 380;
	g_pTextInfor->DrawText(NULL, L"˵:", -1, &formatRect, 
		DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(235,123,230,255));
	formatRect.top += 35;
	g_pTextHelper->DrawText(NULL, L"    ס϶ƽģ", -1, &formatRect, 
		DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(255,200,0,255));
	formatRect.top += 25;
	g_pTextHelper->DrawText(NULL, L"    סҼ϶תģ", -1, &formatRect, 
		DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(255,200,0,255));
	formatRect.top += 25;
	g_pTextHelper->DrawText(NULL, L"    ֣ģ", -1, &formatRect, 
		DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(255,200,0,255));
	formatRect.top += 25;
	g_pTextHelper->DrawText(NULL, L"    WSADƽģ ", -1, &formatRect, 
		DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(255,200,0,255));
	formatRect.top += 25;
	g_pTextHelper->DrawText(NULL, L"    ϡ¡ҷתģ ", -1, &formatRect, 
		DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(255,200,0,255));
	formatRect.top += 25;
	g_pTextHelper->DrawText(NULL, L"    1,2,3,4ּѰַģʽ֮л ", -1, &formatRect, 
		DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(255,200,0,255));
	formatRect.top += 25;
	g_pTextHelper->DrawText(NULL, L"    ESC : ˳", -1, &formatRect, 
		DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(255,200,0,255));


	//--------------------------------------------------------------------------------------
	// Direct3DȾ岽֮ġ
	//--------------------------------------------------------------------------------------
	g_pd3dDevice->EndScene();                       // 
	//--------------------------------------------------------------------------------------
	// Direct3DȾ岽֮塿ʾת
	//--------------------------------------------------------------------------------------
	g_pd3dDevice->Present(NULL, NULL, NULL, NULL);  // תʾ

}



//-----------------------------------Get_FPS( )------------------------------------------
//	ڼÿ֡ʵһ
//--------------------------------------------------------------------------------------------------
float Get_FPS()
{

	//ĸ̬
	static float  fps = 0; //ҪFPSֵ
	static int    frameCount = 0;//֡
	static float  currentTime =0.0f;//ǰʱ
	static float  lastTime = 0.0f;//ʱ

	frameCount++;//ÿһGet_FPS()֡1
	currentTime = timeGetTime()*0.001f;//ȡϵͳʱ䣬timeGetTimeصԺΪλϵͳʱ䣬Ҫ0.001õλΪʱ

	//ǰʱȥʱ1ӣͽһFPSļͳʱĸ£ֵ֡
	if(currentTime - lastTime > 1.0f) //ʱ1
	{
		fps = (float)frameCount /(currentTime - lastTime);//1ӵFPSֵ
		lastTime = currentTime; //ǰʱcurrentTimeʱlastTimeΪһĻ׼ʱ
		frameCount    = 0;//֡frameCountֵ
	}

	return fps;
}



//-----------------------------------Direct3D_CleanUp( )--------------------------------
//	Direct3DԴͷCOMӿڶ
//---------------------------------------------------------------------------------------------------
void Direct3D_CleanUp()
{
	//ͷCOMӿڶ
	SAFE_DELETE(g_pDInput);
	SAFE_RELEASE(g_pVertexBuffer)
		SAFE_RELEASE(g_pIndexBuffer)
		SAFE_RELEASE(g_pMipTexture)
		SAFE_RELEASE(g_pTextAdaperName)
		SAFE_RELEASE(g_pTextHelper)
		SAFE_RELEASE(g_pTextInfor)
		SAFE_RELEASE(g_pTextFPS)
		SAFE_RELEASE(g_pd3dDevice)
}



================================================
FILE: Direct3D-Game-Demo/D3Ddemo11/DirectInputClass.cpp
================================================
//=============================================================================
// Desc: DirectInput봦Դļ
// 2013 203  Create by dzī 
//=============================================================================
#include "DirectInputClass.h"


//-----------------------------------------------------------------------------
// Desc: 캯
//-----------------------------------------------------------------------------
DInputClass::DInputClass()
{
	m_pDirectInput = NULL;
	m_KeyboardDevice = NULL;
	ZeroMemory(m_keyBuffer,sizeof(char)*256);
	m_MouseDevice= NULL;
	ZeroMemory(&m_MouseState, sizeof(m_MouseState));
}


//-----------------------------------------------------------------------------
// NameDInputClass::Init(
// Desc: ʼDirectInput̼豸
//-----------------------------------------------------------------------------
HRESULT DInputClass::Init( HWND hWnd,HINSTANCE hInstance,DWORD keyboardCoopFlags, DWORD mouseCoopFlags )
{
	HRESULT hr;
	//ʼһIDirectInput8ӿڶ
	HR(DirectInput8Create( hInstance, DIRECTINPUT_VERSION, 
		IID_IDirectInput8,(void**)&m_pDirectInput,NULL ));

	//м豸ijʼ
	HR( m_pDirectInput->CreateDevice( GUID_SysKeyboard, &m_KeyboardDevice, NULL ));
	HR( m_KeyboardDevice->SetCooperativeLevel( hWnd, keyboardCoopFlags));
	HR( m_KeyboardDevice->SetDataFormat( &c_dfDIKeyboard ));
	HR( m_KeyboardDevice->Acquire( ));
	HR( m_KeyboardDevice->Poll( ));

	//豸ijʼ
	HR( m_pDirectInput->CreateDevice( GUID_SysMouse, &m_MouseDevice, NULL ));
	HR( m_MouseDevice->SetCooperativeLevel( hWnd,mouseCoopFlags));
	HR( m_MouseDevice->SetDataFormat( &c_dfDIMouse ));
	HR( m_MouseDevice->Acquire( ));
	HR( m_KeyboardDevice->Poll( ));

	return S_OK;
}


//-----------------------------------------------------------------------------
// NameDInputClass::GetInput()
// Desc: ڻȡϢĺ
//-----------------------------------------------------------------------------
void DInputClass::GetInput()
{
	HRESULT hr = m_KeyboardDevice->GetDeviceState(sizeof(m_keyBuffer), (void**)&m_keyBuffer); 
	//ȡϢ
	if(hr)
	{
		m_KeyboardDevice->Acquire();  
		m_KeyboardDevice->GetDeviceState( sizeof(m_keyBuffer),(LPVOID)m_keyBuffer );
	}

	hr = m_MouseDevice->GetDeviceState(sizeof(DIMOUSESTATE), (void**)&m_MouseState); 
	//ȡϢ
	if(hr)
	{
		m_MouseDevice->Acquire();
		m_MouseDevice->GetDeviceState( sizeof(DIMOUSESTATE), (void**)&m_MouseState);
	}
}

//-----------------------------------------------------------------------------
// NameDInputClass::IsKeyDown()
// Desc: жϼijǷ
//-----------------------------------------------------------------------------
bool DInputClass::IsKeyDown(int iKey)
{
	if(m_keyBuffer[iKey] & 0x80)
		return true;
	else
		return false;
}


//-----------------------------------------------------------------------------
// NameDInputClass::IsMouseButtonDown()
// Desc: жijǷ
//-----------------------------------------------------------------------------
bool DInputClass::IsMouseButtonDown(int button)
{
	return (m_MouseState.rgbButtons[button] & 0x80) != 0;
}

//-----------------------------------------------------------------------------
// NameDInputClass::MouseDX
// Desc: ָXֵ
//-----------------------------------------------------------------------------
float DInputClass::MouseDX()
{
	return (float)m_MouseState.lX;
}

//-----------------------------------------------------------------------------
// NameDInputClass::MouseDY
// Desc: ָYֵ
//-----------------------------------------------------------------------------
float DInputClass::MouseDY()
{
	return (float)m_MouseState.lY;
}

//-----------------------------------------------------------------------------
// NameDInputClass::MouseDZ
// Desc: ָZֵ֣
//-----------------------------------------------------------------------------
float DInputClass::MouseDZ()
{
	return (float)m_MouseState.lZ;
}




//-----------------------------------------------------------------------------
// Desc: 
//-----------------------------------------------------------------------------
DInputClass::~DInputClass(void)
{
	if(m_KeyboardDevice != NULL)
		m_KeyboardDevice->Unacquire();
	if(m_MouseDevice != NULL)
		m_MouseDevice->Unacquire();
	SAFE_RELEASE(m_KeyboardDevice);
	SAFE_RELEASE(m_MouseDevice);
	SAFE_RELEASE(m_pDirectInput);
}


================================================
FILE: Direct3D-Game-Demo/D3Ddemo11/DirectInputClass.h
================================================
//=============================================================================
// Name: DirectInputClass.h
//	Des: װDirectInput봦ͷļ
// 2013 203  Create by dzī 
//=============================================================================
#pragma once
#include "D3DUtil.h"
#define DIRECTINPUT_VERSION 0x0800
#include <dinput.h>

//DInputClassඨ忪ʼ
class DInputClass
{
private:
	IDirectInput8					* m_pDirectInput;   //IDirectInput8ӿڶ
	IDirectInputDevice8		* m_KeyboardDevice;  //豸ӿڶ
	char								m_keyBuffer[256];       //ڼֵ̼洢

	IDirectInputDevice8		*m_MouseDevice;      //豸ӿڶ
	DIMOUSESTATE				m_MouseState;			//ֵ洢һṹ

public:
	HRESULT		Init( HWND hWnd,HINSTANCE hInstance,DWORD keyboardCoopFlags, DWORD mouseCoopFlags ); //ʼDirectInput̼豸
	void				GetInput();   //ڻȡϢĺ
	bool				IsKeyDown(int iKey);   //жϼijǷ
	
	bool				IsMouseButtonDown(int button);  //ж갴Ƿ񱻰
	float				MouseDX();   //Xֵ
	float				MouseDY();	//Yֵ
	float				MouseDZ();	//Zֵ


public:
	DInputClass(void);		//캯
	~DInputClass(void);	//
};


================================================
FILE: Direct3D-Game-Demo/D3Ddemo12/D3DUtil.h
================================================

//*****************************************************************************************
// Desc: D3DUtil.hͷļڹĶ
// 2013 203  Create by dzī 
//*****************************************************************************************

#pragma once


#ifndef HR
#define HR(x)    { hr = x; if( FAILED(hr) ) { return hr; } }         //ԶһHRִ꣬дķ
#endif

#ifndef SAFE_DELETE					
#define SAFE_DELETE(p)       { if(p) { delete (p);     (p)=NULL; } }       //ԶһSAFE_RELEASE(),ָԴͷ
#endif    

#ifndef SAFE_RELEASE			
#define SAFE_RELEASE(p)      { if(p) { (p)->Release(); (p)=NULL; } }     //ԶһSAFE_RELEASE(),COMԴͷ
#endif

================================================
FILE: Direct3D-Game-Demo/D3Ddemo12/D3Ddemo12.cpp
================================================
//-----------------------------------˵----------------------------------------------
//  :D3Ddemo12
//	 20134 Create by dzī
//  ģͺXļʹ ʾ
//  ͼزģ ɽǰ 
//------------------------------------------------------------------------------------------------

//-----------------------------------궨岿֡--------------------------------------------
// һЩ
//------------------------------------------------------------------------------------------------
#define WINDOW_WIDTH	800						//Ϊڿȶĺ꣬Էڴ˴޸Ĵڿ
#define WINDOW_HEIGHT	600							//Ϊڸ߶ȶĺ꣬Էڴ˴޸Ĵڸ߶
#define WINDOW_TITLE	_T("ϨϷ롿  ģͺXļʹ ʾ") //Ϊڱⶨĺ


//-----------------------------------ͷļ֡---------------------------------------
//	ͷļ
//------------------------------------------------------------------------------------------------                                                                                    
#include <d3d9.h>
#include <d3dx9.h>
#include <tchar.h>
#include <time.h> 
#include "DirectInputClass.h"



//-----------------------------------ļ֡---------------------------------------
//	Ŀļ
//------------------------------------------------------------------------------------------------
#pragma comment(lib,"d3d9.lib")
#pragma comment(lib,"d3dx9.lib")
#pragma comment(lib, "dinput8.lib")     // ʹDirectInputĿļע8
#pragma comment(lib,"dxguid.lib")
#pragma comment(lib, "winmm.lib") 




//-----------------------------------ȫֱ֡-------------------------------------
//	ȫֱ
//------------------------------------------------------------------------------------------------
LPDIRECT3DDEVICE9					g_pd3dDevice = NULL; //Direct3D豸
LPD3DXFONT								g_pTextFPS				=NULL;    //COMӿ
LPD3DXFONT								g_pTextAdaperName           = NULL;  // ԿϢ2Dı
LPD3DXFONT								g_pTextHelper          = NULL;  // Ϣ2Dı
LPD3DXFONT								g_pTextInfor           = NULL;  // Ϣ2Dı
float											g_FPS								= 0.0f;       //һ͵ı֡
wchar_t										g_strFPS[50]={0};    //֡ʵַ
wchar_t										g_strAdapterName[60]={0};    //ԿƵַ
D3DXMATRIX							g_matWorld;   //
DInputClass*								g_pDInput = NULL;         //һDInputClassָ

LPD3DXMESH				g_pMesh     = NULL; // 
D3DMATERIAL9*			g_pMaterials    = NULL; // IJϢ
LPDIRECT3DTEXTURE9*	g_pTextures     = NULL; // Ϣ
DWORD						g_dwNumMtrls    = 0;    // ʵĿ


//-----------------------------------ȫֺ֡-------------------------------------
//	ȫֺֹδıʶϵд
//------------------------------------------------------------------------------------------------
LRESULT CALLBACK		WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam );
HRESULT						Direct3D_Init(HWND hwnd,HINSTANCE hInstance);
HRESULT						Objects_Init();
void								Direct3D_Render( HWND hwnd);
void								Direct3D_Update( HWND hwnd);
void								Direct3D_CleanUp( );
float								Get_FPS();
void								Matrix_Set();


//-----------------------------------WinMain( )--------------------------------------
//	WindowsӦóںǵij↑ʼ
//------------------------------------------------------------------------------------------------
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nShowCmd)
{
	//1ڴIJ֮һʼһĴ
	WNDCLASSEX wndClass = { 0 };							//WINDCLASSEXһ
	wndClass.cbSize = sizeof( WNDCLASSEX ) ;			//ýṹֽС
	wndClass.style = CS_HREDRAW | CS_VREDRAW;	//ôڵʽ
	wndClass.lpfnWndProc = WndProc;					//ָ򴰿ڹָ̺
	wndClass.cbClsExtra		= 0;								//ĸڴ棬ȡ0Ϳ
	wndClass.cbWndExtra		= 0;							//ڵĸڴ棬Ȼȡ0
	wndClass.hInstance = hInstance;						//ָڹ̵ijʵ
	wndClass.hIcon=(HICON)::LoadImage(NULL,L"icon.ico",IMAGE_ICON,0,0,LR_DEFAULTSIZE|LR_LOADFROMFILE);  //ؼԶicoͼ
	wndClass.hCursor = LoadCursor( NULL, IDC_ARROW );    //ָĹ
	wndClass.hbrBackground=(HBRUSH)GetStockObject(GRAY_BRUSH);  //ΪhbrBackgroundԱָһɫˢ	
	wndClass.lpszMenuName = NULL;						//һԿַָֹ˵Դ֡
	wndClass.lpszClassName = L"ForTheDreamOfGameDevelop";		//һԿַָֹ֡

	//2ڴIJ֮עᴰ
	if( !RegisterClassEx( &wndClass ) )				//괰ںҪԴעᣬܴ͵Ĵ
		return -1;		

	//3ڴIJ֮ʽ
	HWND hwnd = CreateWindow( L"ForTheDreamOfGameDevelop",WINDOW_TITLE,				//ϲּĴںCreateWindow
		WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, WINDOW_WIDTH,
		WINDOW_HEIGHT, NULL, NULL, hInstance, NULL );

	//Direct3DԴijʼʧmessageboxʾ
	if (!(S_OK==Direct3D_Init (hwnd,hInstance)))
	{
		MessageBox(hwnd, _T("Direct3Dʼʧ~"), _T("dzīϢ"), 0); //ʹMessageBoxһϢ 
	}

	//4ڴIJ֮ģڵƶʾ
	MoveWindow(hwnd,250,80,WINDOW_WIDTH,WINDOW_HEIGHT,true);		//ʾʱλãʹϽλڣ250,80
	ShowWindow( hwnd, nShowCmd );    //ShowWindowʾ
	UpdateWindow(hwnd);						//Դڽи£·Ҫװһ

	//DirectInputijʼ
	g_pDInput = new DInputClass();
	g_pDInput->Init(hwnd,hInstance,DISCL_FOREGROUND | DISCL_NONEXCLUSIVE,DISCL_FOREGROUND | DISCL_NONEXCLUSIVE); //ǰ̨Ƕռģʽ
	PlaySound(L"ɽ.wav", NULL, SND_FILENAME | SND_ASYNC|SND_LOOP); //ѭű 

	//5Ϣѭ
	MSG msg = { 0 };  //ʼmsg
	while( msg.message != WM_QUIT )			//ʹwhileѭ
	{
		if( PeekMessage( &msg, 0, 0, 0, PM_REMOVE ) )   //鿴ӦóϢУϢʱеϢɷȥ
		{
			TranslateMessage( &msg );		//ϢתΪַϢ
			DispatchMessage( &msg );		//úַһϢڳ
		}
		else
		{
			Direct3D_Update(hwnd);			//øºлĸ
			Direct3D_Render(hwnd);			//ȾлȾ	
		}
	}
	//6ע
	UnregisterClass(L"ForTheDreamOfGameDevelop", wndClass.hInstance);  //׼ע
	return 0;  
}



//-----------------------------------WndProc( )--------------------------------------
//	ڹ̺WndProc,ԴϢд
//------------------------------------------------------------------------------------------------
LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )   //ڹ̺WndProc
{
	switch( message )				//switch俪ʼ
	{
	case WM_PAINT:					 // ͻػϢ
		Direct3D_Render(hwnd);          //Direct3D_RenderлĻ
		ValidateRect(hwnd, NULL);   // ¿ͻʾ
		break;									//switch

	case WM_KEYDOWN:                // ̰Ϣ
		if (wParam == VK_ESCAPE)    // ESC
			DestroyWindow(hwnd);    // ٴ, һWM_DESTROYϢ
		break;
	case WM_DESTROY:				//Ϣ
		Direct3D_CleanUp();     //Direct3D_CleanUpCOMӿڶ
		PostQuitMessage( 0 );		//ϵͳиֹ߳ӦWM_DESTROYϢ
		break;						//switch

	default:						//caseϣִиdefault
		return DefWindowProc( hwnd, message, wParam, lParam );		//ȱʡĴڹΪӦóûдĴϢṩȱʡĴ
	}

	return 0;					//˳
}


//-----------------------------------Direct3D_Init( )----------------------------------
//	Direct3DʼDirect3Dijʼ
//------------------------------------------------------------------------------------------------
HRESULT Direct3D_Init(HWND hwnd,HINSTANCE hInstance)
{

	//--------------------------------------------------------------------------------------
	// Direct3DʼIJ֮һӿڡDirect3Dӿڶ, ԱøDirect3D󴴽Direct3D豸
	//--------------------------------------------------------------------------------------
	LPDIRECT3D9  pD3D = NULL; //Direct3DӿڶĴ
	if( NULL == ( pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) ) //ʼDirect3Dӿڶ󣬲DirectX汾Э
 			return E_FAIL;

	//--------------------------------------------------------------------------------------
	// Direct3DʼIJ֮,ȡϢȡӲ豸Ϣ
	//--------------------------------------------------------------------------------------
	D3DCAPS9 caps; int vp = 0;
	if( FAILED( pD3D->GetDeviceCaps( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &caps ) ) )
		{
			return E_FAIL;
		}
	if( caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT )
		vp = D3DCREATE_HARDWARE_VERTEXPROCESSING;   //֧Ӳ㣬ǾͲӲ㣬׵
	else
		vp = D3DCREATE_SOFTWARE_VERTEXPROCESSING; //֧Ӳ㣬ֻò

	//--------------------------------------------------------------------------------------
	// Direct3DʼIJ֮ݡD3DPRESENT_PARAMETERSṹ
	//--------------------------------------------------------------------------------------
	D3DPRESENT_PARAMETERS d3dpp; 
	ZeroMemory(&d3dpp, sizeof(d3dpp));
	d3dpp.BackBufferWidth            = WINDOW_WIDTH;
	d3dpp.BackBufferHeight           = WINDOW_HEIGHT;
	d3dpp.BackBufferFormat           = D3DFMT_A8R8G8B8;
	d3dpp.BackBufferCount            = 2;
	d3dpp.MultiSampleType            = D3DMULTISAMPLE_NONE;
	d3dpp.MultiSampleQuality         = 0;
	d3dpp.SwapEffect                 = D3DSWAPEFFECT_DISCARD; 
	d3dpp.hDeviceWindow              = hwnd;
	d3dpp.Windowed                   = true;
	d3dpp.EnableAutoDepthStencil     = true; 
	d3dpp.AutoDepthStencilFormat     = D3DFMT_D24S8;
	d3dpp.Flags                      = 0;
	d3dpp.FullScreen_RefreshRateInHz = 0;
	d3dpp.PresentationInterval       = D3DPRESENT_INTERVAL_IMMEDIATE;

	//--------------------------------------------------------------------------------------
	// Direct3DʼIJ֮ģ豸Direct3D豸ӿ
	//--------------------------------------------------------------------------------------
	if(FAILED(pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, 
		hwnd, vp, &d3dpp, &g_pd3dDevice)))
		return E_FAIL;


	//ȡԿϢg_strAdapterNameУԿ֮ǰϡǰԿͺţַ
	 wchar_t TempName[60]=L"ǰԿͺţ";   //һʱַҷ˰"ǰԿͺţ"ַǵĿַ
	 D3DADAPTER_IDENTIFIER9 Adapter;  //һD3DADAPTER_IDENTIFIER9ṹ壬ڴ洢ԿϢ
	 pD3D->GetAdapterIdentifier(0,0,&Adapter);//GetAdapterIdentifierȡԿϢ
	 int len = MultiByteToWideChar(CP_ACP,0, Adapter.Description, -1, NULL, 0);//ԿѾAdapter.DescriptionˣΪcharͣҪתΪwchar_t
	 MultiByteToWideChar(CP_ACP, 0, Adapter.Description, -1, g_strAdapterName, len);//ⲽɺg_strAdapterNameоΪǰǵԿwchar_tַ
	 wcscat_s(TempName,g_strAdapterName);//ѵǰǵԿӵǰԿͺţַ棬TempName
	 wcscpy_s(g_strAdapterName,TempName);//TempNameеĽȫֱg_strAdapterNameУ󹦸~

	if(!(S_OK==Objects_Init())) return E_FAIL;

	SAFE_RELEASE(pD3D) //LPDIRECT3D9ӿڶʹɣǽͷŵ

	return S_OK;
}

//-----------------------------------Object_Init( )--------------------------------------
//	ȾԴʼڴ˺нҪȾԴijʼ
//--------------------------------------------------------------------------------------------------
HRESULT Objects_Init()
{
	//
	D3DXCreateFont(g_pd3dDevice, 36, 0, 0, 1000, false, DEFAULT_CHARSET, 
		OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, 0, _T("Calibri"), &g_pTextFPS);
	D3DXCreateFont(g_pd3dDevice, 20, 0, 1000, 0, false, DEFAULT_CHARSET, 
		OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, 0, L"", &g_pTextAdaperName); 
	D3DXCreateFont(g_pd3dDevice, 23, 0, 1000, 0, false, DEFAULT_CHARSET, 
		OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, 0, L"΢ź", &g_pTextHelper); 
	D3DXCreateFont(g_pd3dDevice, 26, 0, 1000, 0, false, DEFAULT_CHARSET, 
		OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, 0, L"", &g_pTextInfor); 



	// Xļм
	LPD3DXBUFFER pAdjBuffer  = NULL;
	LPD3DXBUFFER pMtrlBuffer = NULL;

	D3DXLoadMeshFromX(L"miki.X", D3DXMESH_MANAGED, g_pd3dDevice, 
		&pAdjBuffer, &pMtrlBuffer, NULL, &g_dwNumMtrls, &g_pMesh);

	// ȡʺ
	D3DXMATERIAL *pMtrls = (D3DXMATERIAL*)pMtrlBuffer->GetBufferPointer(); //һD3DXMATERIALṹڶȡʺϢ
	g_pMaterials = new D3DMATERIAL9[g_dwNumMtrls];
	g_pTextures  = new LPDIRECT3DTEXTURE9[g_dwNumMtrls];

	for (DWORD i=0; i<g_dwNumMtrls; i++) 
	{
		//ȡʣһ»ɫֵ
		g_pMaterials[i] = pMtrls[i].MatD3D;
		g_pMaterials[i].Ambient = g_pMaterials[i].Diffuse;

		//һ
		g_pTextures[i]  = NULL;
		D3DXCreateTextureFromFileA(g_pd3dDevice, pMtrls[i].pTextureFilename, &g_pTextures[i]);
	}

	SAFE_RELEASE(pAdjBuffer)
	SAFE_RELEASE(pMtrlBuffer)


	// ù
	D3DLIGHT9 light;
	::ZeroMemory(&light, sizeof(light));
	light.Type          = D3DLIGHT_DIRECTIONAL;
	light.Ambient       = D3DXCOLOR(0.5f, 0.5f, 0.5f, 1.0f);
	light.Diffuse       = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	light.Specular      = D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f);
	light.Direction     = D3DXVECTOR3(1.0f, 0.0f, 1.0f);
	g_pd3dDevice->SetLight(0, &light);
	g_pd3dDevice->LightEnable(0, true);
	g_pd3dDevice->SetRenderState(D3DRS_NORMALIZENORMALS, true);
	g_pd3dDevice->SetRenderState(D3DRS_SPECULARENABLE, true);

	// Ⱦ״̬
	g_pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);   //

	return S_OK;
}


//-----------------------------------Matrix_Set( )--------------------------------------
//	װDirect3DĴ任ĺ任ȡ任ͶӰ任ӿڱ任
//--------------------------------------------------------------------------------------------------
void Matrix_Set()
{
	//--------------------------------------------------------------------------------------
	//Ĵ任֮һ任
	//--------------------------------------------------------------------------------------


	//--------------------------------------------------------------------------------------
	//Ĵ任֮ȡ任
	//--------------------------------------------------------------------------------------
	D3DXMATRIX matView; //һ
	D3DXVECTOR3 vEye(0.0f, 0.0f, -250.0f);  //λ
	D3DXVECTOR3 vAt(0.0f, 0.0f, 0.0f); //۲λ
	D3DXVECTOR3 vUp(0.0f, 1.0f, 0.0f);//ϵ
	D3DXMatrixLookAtLH(&matView, &vEye, &vAt, &vUp); //ȡ任
	g_pd3dDevice->SetTransform(D3DTS_VIEW, &matView); //Ӧȡ任

	//--------------------------------------------------------------------------------------
	//Ĵ任֮ͶӰ任
	//--------------------------------------------------------------------------------------
	D3DXMATRIX matProj; //һ
	D3DXMatrixPerspectiveFovLH(&matProj, D3DX_PI / 4.0f,(float)((double)WINDOW_WIDTH/WINDOW_HEIGHT),1.0f, 1000.0f); //ͶӰ任
	g_pd3dDevice->SetTransform(D3DTS_PROJECTION, &matProj);  //ͶӰ任

	//--------------------------------------------------------------------------------------
	//Ĵ任֮ġӿڱ任
	//--------------------------------------------------------------------------------------
	D3DVIEWPORT9 vp; //ʵһD3DVIEWPORT9ṹ壬ȻֵͿ
	vp.X      = 0;		//ʾӿڴڵX
	vp.Y      = 0;		//ӿԶԴڵY
	vp.Width  = WINDOW_WIDTH;	//ӿڵĿ
	vp.Height = WINDOW_HEIGHT; //ӿڵĸ߶
	vp.MinZ   = 0.0f; //ӿȻеСֵ
	vp.MaxZ   = 1.0f;	//ӿȻеֵ
	g_pd3dDevice->SetViewport(&vp); //ӿڵ

}


//-----------------------------------Direct3D_Update( )--------------------------------
//	ǼʱȾ뵫Ҫʱõģ簴ĸģ
//--------------------------------------------------------------------------------------------------
void		Direct3D_Update( HWND hwnd)
{
	//ʹDirectInputȡ
	g_pDInput->GetInput();

	// ס϶ΪƽƲ
	static FLOAT fPosX = 0.0f, fPosY = 0.0f, fPosZ = 0.0f;
	
	if (g_pDInput->IsMouseButtonDown(0)) 
	{
		fPosX += (g_pDInput->MouseDX())*  0.08f;
		fPosY += (g_pDInput->MouseDY()) * -0.08f;
	}

	//֣Ϊ۲
	fPosZ += (g_pDInput->MouseDZ())* 0.02f;

	// ƽ
	if (g_pDInput->IsKeyDown(DIK_A)) fPosX -= 0.005f;
	if (g_pDInput->IsKeyDown(DIK_D)) fPosX += 0.005f;
	if (g_pDInput->IsKeyDown(DIK_W)) fPosY += 0.005f;
	if (g_pDInput->IsKeyDown(DIK_S)) fPosY -= 0.005f;


	D3DXMatrixTranslation(&g_matWorld, fPosX, fPosY, fPosZ);


	// סҼ϶Ϊת
	static float fAngleX = 0, fAngleY =0;
	
	if (g_pDInput->IsMouseButtonDown(1)) 
	{
		fAngleX += (g_pDInput->MouseDY())* -0.01f;
		fAngleY += (g_pDInput->MouseDX()) * -0.01f;
	}
	// ת
 	if (g_pDInput->IsKeyDown(DIK_UP)) fAngleX += 0.005f;
	if (g_pDInput->IsKeyDown(DIK_DOWN)) fAngleX -= 0.005f;
 	if (g_pDInput->IsKeyDown(DIK_LEFT)) fAngleY -= 0.005f;
 	if (g_pDInput->IsKeyDown(DIK_RIGHT)) fAngleY += 0.005f;


	D3DXMATRIX Rx, Ry;
	D3DXMatrixRotationX(&Rx, fAngleX);
	D3DXMatrixRotationY(&Ry, fAngleY);

	g_matWorld = Rx * Ry * g_matWorld;
	g_pd3dDevice->SetTransform(D3DTS_WORLD, &g_matWorld);
	Matrix_Set();
}


//-----------------------------------Direct3D_Render( )-------------------------------
//	ʹDirect3DȾ
//--------------------------------------------------------------------------------------------------
void Direct3D_Render(HWND hwnd)
{

	//--------------------------------------------------------------------------------------
	// Direct3DȾ岽֮һ
	//--------------------------------------------------------------------------------------
	g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(150, 150, 100), 1.0f, 0);

	//һΣڻȡھ
	RECT formatRect;
	GetClientRect(hwnd, &formatRect);

	//--------------------------------------------------------------------------------------
	// Direct3DȾ岽֮ʼ
	//--------------------------------------------------------------------------------------
	g_pd3dDevice->BeginScene();                     // ʼ
	
			//--------------------------------------------------------------------------------------
			// Direct3DȾ岽֮ʽ
			//--------------------------------------------------------------------------------------

	// һforѭֵĻ
	for (DWORD i = 0; i < g_dwNumMtrls; i++)
	{
		g_pd3dDevice->SetMaterial(&g_pMaterials[i]);
		g_pd3dDevice->SetTexture(0, g_pTextures[i]);
		g_pMesh->DrawSubset(i);
	}

			//ڴϽǴʾÿ֡
			formatRect.top = 5;
			int charCount = swprintf_s(g_strFPS, 20, _T("FPS:%0.3f"), Get_FPS() );
			g_pTextFPS->DrawText(NULL, g_strFPS, charCount , &formatRect, DT_TOP | DT_RIGHT, D3DCOLOR_RGBA(0,239,136,255));

			//ʾԿ
			g_pTextAdaperName->DrawText(NULL,g_strAdapterName, -1, &formatRect, 
				DT_TOP | DT_LEFT, D3DXCOLOR(1.0f, 0.5f, 0.0f, 1.0f));

			// Ϣ
			 formatRect.top = 30;
			static wchar_t strInfo[256] = {0};
			swprintf_s(strInfo,-1, L"ģ: (%.2f, %.2f, %.2f)", g_matWorld._41, g_matWorld._42, g_matWorld._43);
			g_pTextHelper->DrawText(NULL, strInfo, -1, &formatRect, DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(135,239,136,255));

			// Ϣ
			formatRect.left = 0,formatRect.top = 380;
			g_pTextInfor->DrawText(NULL, L"˵:", -1, &formatRect, 
				DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(235,123,230,255));
			formatRect.top += 35;
			g_pTextHelper->DrawText(NULL, L"    ס϶ƽģ", -1, &formatRect, 
				DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(255,200,0,255));
			formatRect.top += 25;
			g_pTextHelper->DrawText(NULL, L"    סҼ϶תģ", -1, &formatRect, 
				DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(255,200,0,255));
			formatRect.top += 25;
			g_pTextHelper->DrawText(NULL, L"    ֣ģ", -1, &formatRect, 
				DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(255,200,0,255));
			formatRect.top += 25;
			g_pTextHelper->DrawText(NULL, L"    WSADƽģ ", -1, &formatRect, 
				DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(255,200,0,255));
			formatRect.top += 25;
			g_pTextHelper->DrawText(NULL, L"    ϡ¡ҷתģ ", -1, &formatRect, 
				DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(255,200,0,255));
			formatRect.top += 25;
			g_pTextHelper->DrawText(NULL, L"    ESC : ˳", -1, &formatRect, 
				DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(255,200,0,255));


	//--------------------------------------------------------------------------------------
	// Direct3DȾ岽֮ġ
	//--------------------------------------------------------------------------------------
	g_pd3dDevice->EndScene();                       // 
	//--------------------------------------------------------------------------------------
	// Direct3DȾ岽֮塿ʾת
	//--------------------------------------------------------------------------------------
	g_pd3dDevice->Present(NULL, NULL, NULL, NULL);  // תʾ
	 
}


//-----------------------------------Get_FPS( )------------------------------------------
//	ڼÿ֡ʵһ
//--------------------------------------------------------------------------------------------------
float Get_FPS()
{

	//ĸ̬
	static float  fps = 0; //ҪFPSֵ
	static int    frameCount = 0;//֡
	static float  currentTime =0.0f;//ǰʱ
	static float  lastTime = 0.0f;//ʱ

	frameCount++;//ÿһGet_FPS()֡1
	currentTime = timeGetTime()*0.001f;//ȡϵͳʱ䣬timeGetTimeصԺΪλϵͳʱ䣬Ҫ0.001õλΪʱ

	//ǰʱȥʱ1ӣͽһFPSļͳʱĸ£ֵ֡
	if(currentTime - lastTime > 1.0f) //ʱ1
	{
		fps = (float)frameCount /(currentTime - lastTime);//1ӵFPSֵ
		lastTime = currentTime; //ǰʱcurrentTimeʱlastTimeΪһĻ׼ʱ
		frameCount    = 0;//֡frameCountֵ
	}

	return fps;
}



//-----------------------------------Direct3D_CleanUp( )--------------------------------
//	Direct3DԴͷCOMӿڶ
//---------------------------------------------------------------------------------------------------
void Direct3D_CleanUp()
{
	//ͷCOMӿڶ
	for (DWORD i = 0; i<g_dwNumMtrls; i++) 
		SAFE_RELEASE(g_pTextures[i]);
	SAFE_DELETE(g_pTextures); 
	SAFE_DELETE(g_pMaterials); 
	SAFE_RELEASE(g_pMesh);
	SAFE_RELEASE(g_pd3dDevice);
	SAFE_DELETE(g_pDInput);
	SAFE_RELEASE(g_pTextAdaperName)
	SAFE_RELEASE(g_pTextHelper)
	SAFE_RELEASE(g_pTextInfor)
	SAFE_RELEASE(g_pTextFPS)
	SAFE_RELEASE(g_pd3dDevice)
}

================================================
FILE: Direct3D-Game-Demo/D3Ddemo12/DirectInputClass.cpp
================================================
//=============================================================================
// Desc: DirectInput봦Դļ
// 2013 203  Create by dzī 
//=============================================================================
#include "DirectInputClass.h"


//-----------------------------------------------------------------------------
// Desc: 캯
//-----------------------------------------------------------------------------
DInputClass::DInputClass()
{
	m_pDirectInput = NULL;
	m_KeyboardDevice = NULL;
	ZeroMemory(m_keyBuffer,sizeof(char)*256);
	m_MouseDevice= NULL;
	ZeroMemory(&m_MouseState, sizeof(m_MouseState));
}


//-----------------------------------------------------------------------------
// NameDInputClass::Init(
// Desc: ʼDirectInput̼豸
//-----------------------------------------------------------------------------
HRESULT DInputClass::Init( HWND hWnd,HINSTANCE hInstance,DWORD keyboardCoopFlags, DWORD mouseCoopFlags )
{
	HRESULT hr;
	//ʼһIDirectInput8ӿڶ
	HR(DirectInput8Create( hInstance, DIRECTINPUT_VERSION, 
		IID_IDirectInput8,(void**)&m_pDirectInput,NULL ));

	//м豸ijʼ
	HR( m_pDirectInput->CreateDevice( GUID_SysKeyboard, &m_KeyboardDevice, NULL ));
	HR( m_KeyboardDevice->SetCooperativeLevel( hWnd, keyboardCoopFlags));
	HR( m_KeyboardDevice->SetDataFormat( &c_dfDIKeyboard ));
	HR( m_KeyboardDevice->Acquire( ));
	HR( m_KeyboardDevice->Poll( ));

	//豸ijʼ
	HR( m_pDirectInput->CreateDevice( GUID_SysMouse, &m_MouseDevice, NULL ));
	HR( m_MouseDevice->SetCooperativeLevel( hWnd,mouseCoopFlags));
	HR( m_MouseDevice->SetDataFormat( &c_dfDIMouse ));
	HR( m_MouseDevice->Acquire( ));
	HR( m_KeyboardDevice->Poll( ));

	return S_OK;
}


//-----------------------------------------------------------------------------
// NameDInputClass::GetInput()
// Desc: ڻȡϢĺ
//-----------------------------------------------------------------------------
void DInputClass::GetInput()
{
	HRESULT hr = m_KeyboardDevice->GetDeviceState(sizeof(m_keyBuffer), (void**)&m_keyBuffer); 
	//ȡϢ
	if(hr)
	{
		m_KeyboardDevice->Acquire();  
		m_KeyboardDevice->GetDeviceState( sizeof(m_keyBuffer),(LPVOID)m_keyBuffer );
	}

	hr = m_MouseDevice->GetDeviceState(sizeof(DIMOUSESTATE), (void**)&m_MouseState); 
	//ȡϢ
	if(hr)
	{
		m_MouseDevice->Acquire();
		m_MouseDevice->GetDeviceState( sizeof(DIMOUSESTATE), (void**)&m_MouseState);
	}
}

//-----------------------------------------------------------------------------
// NameDInputClass::IsKeyDown()
// Desc: жϼijǷ
//-----------------------------------------------------------------------------
bool DInputClass::IsKeyDown(int iKey)
{
	if(m_keyBuffer[iKey] & 0x80)
		return true;
	else
		return false;
}


//-----------------------------------------------------------------------------
// NameDInputClass::IsMouseButtonDown()
// Desc: жijǷ
//-----------------------------------------------------------------------------
bool DInputClass::IsMouseButtonDown(int button)
{
	return (m_MouseState.rgbButtons[button] & 0x80) != 0;
}

//-----------------------------------------------------------------------------
// NameDInputClass::MouseDX
// Desc: ָXֵ
//-----------------------------------------------------------------------------
float DInputClass::MouseDX()
{
	return (float)m_MouseState.lX;
}

//-----------------------------------------------------------------------------
// NameDInputClass::MouseDY
// Desc: ָYֵ
//-----------------------------------------------------------------------------
float DInputClass::MouseDY()
{
	return (float)m_MouseState.lY;
}

//-----------------------------------------------------------------------------
// NameDInputClass::MouseDZ
// Desc: ָZֵ֣
//-----------------------------------------------------------------------------
float DInputClass::MouseDZ()
{
	return (float)m_MouseState.lZ;
}




//-----------------------------------------------------------------------------
// Desc: 
//-----------------------------------------------------------------------------
DInputClass::~DInputClass(void)
{
	if(m_KeyboardDevice != NULL)
		m_KeyboardDevice->Unacquire();
	if(m_MouseDevice != NULL)
		m_MouseDevice->Unacquire();
	SAFE_RELEASE(m_KeyboardDevice);
	SAFE_RELEASE(m_MouseDevice);
	SAFE_RELEASE(m_pDirectInput);
}


================================================
FILE: Direct3D-Game-Demo/D3Ddemo12/DirectInputClass.h
================================================
//=============================================================================
// Name: DirectInputClass.h
//	Des: װDirectInput봦ͷļ
// 2013 203  Create by dzī 
//=============================================================================
#pragma once
#include "D3DUtil.h"
#define DIRECTINPUT_VERSION 0x0800
#include <dinput.h>

//DInputClassඨ忪ʼ
class DInputClass
{
private:
	IDirectInput8					* m_pDirectInput;   //IDirectInput8ӿڶ
	IDirectInputDevice8		* m_KeyboardDevice;  //豸ӿڶ
	char								m_keyBuffer[256];       //ڼֵ̼洢

	IDirectInputDevice8		*m_MouseDevice;      //豸ӿڶ
	DIMOUSESTATE				m_MouseState;			//ֵ洢һṹ

public:
	HRESULT		Init( HWND hWnd,HINSTANCE hInstance,DWORD keyboardCoopFlags, DWORD mouseCoopFlags ); //ʼDirectInput̼豸
	void				GetInput();   //ڻȡϢĺ
	bool				IsKeyDown(int iKey);   //жϼijǷ
	
	bool				IsMouseButtonDown(int button);  //ж갴Ƿ񱻰
	float				MouseDX();   //Xֵ
	float				MouseDY();	//Yֵ
	float				MouseDZ();	//Zֵ


public:
	DInputClass(void);		//캯
	~DInputClass(void);	//
};


================================================
FILE: Direct3D-Game-Demo/D3Ddemo13/D3DUtil.h
================================================

//*****************************************************************************************
// Desc: D3DUtil.hͷļڹĶ
// 2013 203  Create by dzī 
//*****************************************************************************************

#pragma once


#ifndef HR
#define HR(x)    { hr = x; if( FAILED(hr) ) { return hr; } }         //ԶһHRִ꣬дķ
#endif

#ifndef SAFE_DELETE					
#define SAFE_DELETE(p)       { if(p) { delete (p);     (p)=NULL; } }       //ԶһSAFE_RELEASE(),ָԴͷ
#endif    

#ifndef SAFE_RELEASE			
#define SAFE_RELEASE(p)      { if(p) { (p)->Release(); (p)=NULL; } }     //ԶһSAFE_RELEASE(),COMԴͷ
#endif

================================================
FILE: Direct3D-Game-Demo/D3Ddemo13/D3Ddemo13.cpp
================================================
//-----------------------------------˵----------------------------------------------
//  :D3Ddemo13
//	 20134 Create by dzī
//  ˮ齻ڵalphaϼ ʾ
//------------------------------------------------------------------------------------------------


//-----------------------------------궨岿֡--------------------------------------------
// һЩ
//------------------------------------------------------------------------------------------------
#define SCREEN_WIDTH	800						//Ϊڿȶĺ꣬Էڴ˴޸Ĵڿ
#define SCREEN_HEIGHT	600							//Ϊڸ߶ȶĺ꣬Էڴ˴޸Ĵڸ߶
#define WINDOW_TITLE	_T("ϨϷ롿  ˮ齻ڵalphaϼ ʾ") //Ϊڱⶨĺ


//-----------------------------------ͷļ֡---------------------------------------
//	ͷļ
//------------------------------------------------------------------------------------------------                                                                                      
#include <d3d9.h>
#include <d3dx9.h>
#include <tchar.h>
#include <time.h> 
#include "DirectInputClass.h"



//-----------------------------------ļ֡---------------------------------------
//	Ŀļ
//------------------------------------------------------------------------------------------------
#pragma comment(lib,"d3d9.lib")
#pragma comment(lib,"d3dx9.lib")
#pragma comment(lib, "dinput8.lib")     // ʹDirectInputĿļע8
#pragma comment(lib,"dxguid.lib")
#pragma comment(lib, "winmm.lib") 


//-----------------------------------ȫֱ֡-------------------------------------
//	ȫֱ
//------------------------------------------------------------------------------------------------
LPDIRECT3DDEVICE9					g_pd3dDevice = NULL; //Direct3D豸
LPD3DXFONT								g_pTextFPS				=NULL;    //COMӿ
LPD3DXFONT								g_pTextAdaperName           = NULL;  // ԿϢ2Dı
LPD3DXFONT								g_pTextHelper          = NULL;  // Ϣ2Dı
LPD3DXFONT								g_pTextInfor           = NULL;  // Ϣ2Dı
float											g_FPS								= 0.0f;       //һ͵ı֡
wchar_t										g_strFPS[50]={0};    //֡ʵַ
wchar_t										g_strAdapterName[60]={0};    //ԿƵַ
D3DXMATRIX							g_matWorld;   //
DInputClass*								g_pDInput = NULL;         //һDInputClassָ

LPD3DXMESH				g_pMesh     = NULL; // 
D3DMATERIAL9*			g_pMaterials    = NULL; // IJϢ
LPDIRECT3DTEXTURE9*  g_pTextures     = NULL; // Ϣ
DWORD						g_dwNumMtrls    = 0;    // ʵĿ


//-----------------------------------ȫֺ֡-------------------------------------
//	ȫֺֹδıʶϵд
//------------------------------------------------------------------------------------------------
LRESULT CALLBACK		WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam );
HRESULT						Direct3D_Init(HWND hwnd,HINSTANCE hInstance);
HRESULT						Objects_Init();
void								Direct3D_Render( HWND hwnd);
void								Direct3D_Update( HWND hwnd);
void								Direct3D_CleanUp( );
float								Get_FPS();
void								Matrix_Set();


//-----------------------------------WinMain( )--------------------------------------
//	WindowsӦóںǵij↑ʼ
//------------------------------------------------------------------------------------------------
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nShowCmd)
{

	//ʼһĴ
	WNDCLASSEX wndClass = { 0 };				//WINDCLASSEXһ࣬wndClassʵWINDCLASSEX֮󴰿ڵĸʼ    
	wndClass.cbSize = sizeof( WNDCLASSEX ) ;	//ýṹֽС
	wndClass.style = CS_HREDRAW | CS_VREDRAW;	//ôڵʽ
	wndClass.lpfnWndProc = WndProc;				//ָ򴰿ڹָ̺
	wndClass.cbClsExtra		= 0;
	wndClass.cbWndExtra		= 0;
	wndClass.hInstance = hInstance;				//ָڹ̵ijʵ
	wndClass.hIcon=(HICON)::LoadImage(NULL,_T("icon.ico"),IMAGE_ICON,0,0,LR_DEFAULTSIZE|LR_LOADFROMFILE); //ȫֵ::LoadImageӱؼԶicoͼ
	wndClass.hCursor = LoadCursor( NULL, IDC_ARROW );    //ָĹ
	wndClass.hbrBackground=(HBRUSH)GetStockObject(GRAY_BRUSH);  //ΪhbrBackgroundԱָһɫˢ
	wndClass.lpszMenuName = NULL;						//һԿַָֹ˵Դ֡
	wndClass.lpszClassName = _T("ForTheDreamOfGameDevelop");		//һԿַָֹ֡

	if( !RegisterClassEx( &wndClass ) )				//괰ںҪԴעᣬܴ͵Ĵ
		return -1;		

	HWND hwnd = CreateWindow( _T("ForTheDreamOfGameDevelop"),WINDOW_TITLE,			//ϲּĴںCreateWindow
		WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, SCREEN_WIDTH,
		SCREEN_HEIGHT, NULL, NULL, hInstance, NULL );


	//Direct3DԴijʼʧmessageboxʾ
	if (!(S_OK==Direct3D_Init (hwnd,hInstance)))
	{
		MessageBox(hwnd, _T("Direct3Dʼʧ~"), _T("dzīϢ"), 0); //ʹMessageBoxһϢ 
	}
	PlaySound(L"ɽ¥.wav", NULL, SND_FILENAME | SND_ASYNC|SND_LOOP);   //ѭű

	MoveWindow(hwnd,200,50,SCREEN_WIDTH,SCREEN_HEIGHT,true);   //ʾʱλãϽλĻ꣨20050
	ShowWindow( hwnd, nShowCmd );    //Win32ShowWindowʾ
	UpdateWindow(hwnd);  //Դڽи£·Ҫװһ

	//DirectInputijʼ
	g_pDInput = new DInputClass();
	g_pDInput->Init(hwnd,hInstance,DISCL_FOREGROUND | DISCL_NONEXCLUSIVE,DISCL_FOREGROUND | DISCL_NONEXCLUSIVE);

	//Ϣѭ
	MSG msg = { 0 };  //ʼmsg
	while( msg.message != WM_QUIT )			//ʹwhileѭ
	{
		if( PeekMessage( &msg, 0, 0, 0, PM_REMOVE ) )   //鿴ӦóϢУϢʱеϢɷȥ
		{
			TranslateMessage( &msg );		//ϢתΪַϢ
			DispatchMessage( &msg );		//úַһϢڳ
		}
		else
		{
			Direct3D_Update(hwnd);         //øºлĸ
			Direct3D_Render(hwnd);			//ȾлȾ			
		}
	}

	UnregisterClass(_T("ForTheDreamOfGameDevelop"), wndClass.hInstance);
	return 0;  
}



//-----------------------------------WndProc( )--------------------------------------
//	ڹ̺WndProc,ԴϢд
//------------------------------------------------------------------------------------------------
LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )   //ڹ̺WndProc
{
	switch( message )				//switch俪ʼ
	{
	case WM_PAINT:					 // ͻػϢ
		Direct3D_Render(hwnd);          //Direct3D_RenderлĻ
		ValidateRect(hwnd, NULL);   // ¿ͻʾ
		break;									//switch

	case WM_KEYDOWN:                // ̰Ϣ
		if (wParam == VK_ESCAPE)    // ESC
			DestroyWindow(hwnd);    // ٴ, һWM_DESTROYϢ
		break;
	case WM_DESTROY:				//Ϣ
		Direct3D_CleanUp();     //Direct3D_CleanUpCOMӿڶ
		PostQuitMessage( 0 );		//ϵͳиֹ߳ӦWM_DESTROYϢ
		break;						//switch

	default:						//caseϣִиdefault
		return DefWindowProc( hwnd, message, wParam, lParam );		//ȱʡĴڹΪӦóûдĴϢṩȱʡĴ
	}

	return 0;					//˳
}


//-----------------------------------Direct3D_Init( )----------------------------------
//	Direct3DʼDirect3Dijʼ
//------------------------------------------------------------------------------------------------
HRESULT Direct3D_Init(HWND hwnd,HINSTANCE hInstance)
{

	//--------------------------------------------------------------------------------------
	// Direct3DʼIJ֮һӿڡDirect3Dӿڶ, ԱøDirect3D󴴽Direct3D豸
	//--------------------------------------------------------------------------------------
	LPDIRECT3D9  pD3D = NULL; //Direct3DӿڶĴ
	if( NULL == ( pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) ) //ʼDirect3Dӿڶ󣬲DirectX汾Э
 			return E_FAIL;

	//--------------------------------------------------------------------------------------
	// Direct3DʼIJ֮,ȡϢȡӲ豸Ϣ
	//--------------------------------------------------------------------------------------
	D3DCAPS9 caps; int vp = 0;
	if( FAILED( pD3D->GetDeviceCaps( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &caps ) ) )
		{
			return E_FAIL;
		}
	if( caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT )
		vp = D3DCREATE_HARDWARE_VERTEXPROCESSING;   //֧Ӳ㣬ǾͲӲ㣬׵
	else
		vp = D3DCREATE_SOFTWARE_VERTEXPROCESSING; //֧Ӳ㣬ֻò

	//--------------------------------------------------------------------------------------
	// Direct3DʼIJ֮ݡD3DPRESENT_PARAMETERSṹ
	//--------------------------------------------------------------------------------------
	D3DPRESENT_PARAMETERS d3dpp; 
	ZeroMemory(&d3dpp, sizeof(d3dpp));
	d3dpp.BackBufferWidth            = SCREEN_WIDTH;
	d3dpp.BackBufferHeight           = SCREEN_HEIGHT;
	d3dpp.BackBufferFormat           = D3DFMT_A8R8G8B8;
	d3dpp.BackBufferCount            = 2;
	d3dpp.MultiSampleType            = D3DMULTISAMPLE_NONE;
	d3dpp.MultiSampleQuality         = 0;
	d3dpp.SwapEffect                 = D3DSWAPEFFECT_DISCARD; 
	d3dpp.hDeviceWindow              = hwnd;
	d3dpp.Windowed                   = true;
	d3dpp.EnableAutoDepthStencil     = true; 
	d3dpp.AutoDepthStencilFormat     = D3DFMT_D24S8;
	d3dpp.Flags                      = 0;
	d3dpp.FullScreen_RefreshRateInHz = 0;
	d3dpp.PresentationInterval       = D3DPRESENT_INTERVAL_IMMEDIATE;

	//--------------------------------------------------------------------------------------
	// Direct3DʼIJ֮ģ豸Direct3D豸ӿ
	//--------------------------------------------------------------------------------------
	if(FAILED(pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, 
		hwnd, vp, &d3dpp, &g_pd3dDevice)))
		return E_FAIL;


	//ȡԿϢg_strAdapterNameУԿ֮ǰϡǰԿͺţַ
	 wchar_t TempName[60]=L"ǰԿͺţ";   //һʱַҷ˰"ǰԿͺţ"ַǵĿַ
	 D3DADAPTER_IDENTIFIER9 Adapter;  //һD3DADAPTER_IDENTIFIER9ṹ壬ڴ洢ԿϢ
	 pD3D->GetAdapterIdentifier(0,0,&Adapter);//GetAdapterIdentifierȡԿϢ
	 int len = MultiByteToWideChar(CP_ACP,0, Adapter.Description, -1, NULL, 0);//ԿѾAdapter.DescriptionˣΪcharͣҪתΪwchar_t
	 MultiByteToWideChar(CP_ACP, 0, Adapter.Description, -1, g_strAdapterName, len);//ⲽɺg_strAdapterNameоΪǰǵԿwchar_tַ
	 wcscat_s(TempName,g_strAdapterName);//ѵǰǵԿӵǰԿͺţַ棬TempName
	 wcscpy_s(g_strAdapterName,TempName);//TempNameеĽȫֱg_strAdapterNameУ󹦸~

	if(!(S_OK==Objects_Init())) return E_FAIL;

	SAFE_RELEASE(pD3D) //LPDIRECT3D9ӿڶʹɣǽͷŵ

	return S_OK;
}

//-----------------------------------Object_Init( )--------------------------------------
//	ȾԴʼڴ˺нҪȾԴijʼ
//--------------------------------------------------------------------------------------------------
HRESULT Objects_Init()
{
	//
	D3DXCreateFont(g_pd3dDevice, 36, 0, 0, 1000, false, DEFAULT_CHARSET, 
		OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, 0, _T("Calibri"), &g_pTextFPS);
	D3DXCreateFont(g_pd3dDevice, 20, 0, 1000, 0, false, DEFAULT_CHARSET, 
		OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, 0, L"", &g_pTextAdaperName); 
	D3DXCreateFont(g_pd3dDevice, 23, 0, 1000, 0, false, DEFAULT_CHARSET, 
		OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, 0, L"΢ź", &g_pTextHelper); 
	D3DXCreateFont(g_pd3dDevice, 26, 0, 1000, 0, false, DEFAULT_CHARSET, 
		OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, 0, L"", &g_pTextInfor); 

	// Xļм
	LPD3DXBUFFER pAdjBuffer  = NULL;
	LPD3DXBUFFER pMtrlBuffer = NULL;

	D3DXLoadMeshFromX(L"65.X", D3DXMESH_MANAGED, g_pd3dDevice, 
		&pAdjBuffer, &pMtrlBuffer, NULL, &g_dwNumMtrls, &g_pMesh);

	// ȡʺ
	D3DXMATERIAL *pMtrls = (D3DXMATERIAL*)pMtrlBuffer->GetBufferPointer(); //һD3DXMATERIALṹڶȡʺϢ
	g_pMaterials = new D3DMATERIAL9[g_dwNumMtrls];
	g_pTextures  = new LPDIRECT3DTEXTURE9[g_dwNumMtrls];

	for (DWORD i=0; i<g_dwNumMtrls; i++) 
	{
		//ȡʣһ»ɫֵ
		g_pMaterials[i] = pMtrls[i].MatD3D;
		//g_pMaterials[i].Ambient = g_pMaterials[i].Diffuse;

		g_pMaterials[i].Diffuse.a = 0.3f;//òʵAlpha

		//һ
		g_pTextures[i]  = NULL;
		//ע͵룬ḁ́ʵAlphaͨϳĻ
		//D3DXCreateTextureFromFileA(g_pd3dDevice, pMtrls[i].pTextureFilename, &g_pTextures[i]);
	}

	SAFE_RELEASE(pAdjBuffer)
	SAFE_RELEASE(pMtrlBuffer)


	// ù
	D3DLIGHT9 light;
	::ZeroMemory(&light, sizeof(light));
	light.Type          = D3DLIGHT_DIRECTIONAL;
	light.Ambient       = D3DXCOLOR(0.5f, 0.5f, 0.5f, 1.0f);
	light.Diffuse       = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	light.Specular      = D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f);
	light.Direction     = D3DXVECTOR3(1.0f, 0.0f, 1.0f);
	g_pd3dDevice->SetLight(0, &light);
	g_pd3dDevice->LightEnable(0, true);
	g_pd3dDevice->SetRenderState(D3DRS_NORMALIZENORMALS, true);
	g_pd3dDevice->SetRenderState(D3DRS_SPECULARENABLE, true);

	// Ⱦ״̬
	g_pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);   //
	g_pd3dDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESS);   //ȲԺΪD3DCMP_LESS
	g_pd3dDevice->SetRenderState(D3DRS_ZWRITEENABLE, true);     //ȲԳɹ󣬸Ȼ


	// ֮һAlphaں
	g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
	//֮ں
	g_pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
	g_pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
	//֮ں㷽ʽ
	g_pd3dDevice->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD);  //㷽ʽΪD3DBLENDOP_ADDĴDirect3DĬΪдˣע͵Ҳû

	return S_OK;
}


//-----------------------------------Matrix_Set( )--------------------------------------
//	װDirect3DĴ任ĺ任ȡ任ͶӰ任ӿڱ任
//--------------------------------------------------------------------------------------------------
void Matrix_Set()
{

	//--------------------------------------------------------------------------------------
	//Ĵ任֮ȡ任
	//--------------------------------------------------------------------------------------
	D3DXMATRIX matView; //һ
	D3DXVECTOR3 vEye(0.0f, 100.0f, -200.0f);  //λ
	D3DXVECTOR3 vAt(0.0f, 35.0f, 0.0f); //۲λ
	D3DXVECTOR3 vUp(0.0f, 1.0f, 0.0f);//ϵ
	D3DXMatrixLookAtLH(&matView, &vEye, &vAt, &vUp); //ȡ任
	g_pd3dDevice->SetTransform(D3DTS_VIEW, &matView); //Ӧȡ任

	//--------------------------------------------------------------------------------------
	//Ĵ任֮ͶӰ任
	//--------------------------------------------------------------------------------------
	D3DXMATRIX matProj; //һ
	D3DXMatrixPerspectiveFovLH(&matProj, D3DX_PI / 4.0f,(float)((double)SCREEN_WIDTH/SCREEN_HEIGHT),1.0f, 1000.0f); //ͶӰ任
	g_pd3dDevice->SetTransform(D3DTS_PROJECTION, &matProj);  //ͶӰ任

	//--------------------------------------------------------------------------------------
	//Ĵ任֮ġӿڱ任
	//--------------------------------------------------------------------------------------
	D3DVIEWPORT9 vp; //ʵһD3DVIEWPORT9ṹ壬ȻֵͿ
	vp.X      = 0;		//ʾӿڴڵX
	vp.Y      = 0;		//ӿԶԴڵY
	vp.Width  = SCREEN_WIDTH;	//ӿڵĿ
	vp.Height = SCREEN_HEIGHT; //ӿڵĸ߶
	vp.MinZ   = 0.0f; //ӿȻеСֵ
	vp.MaxZ   = 1.0f;	//ӿȻеֵ
	g_pd3dDevice->SetViewport(&vp); //ӿڵ

}

//-----------------------------------Direct3D_Update( )--------------------------------
//	ǼʱȾ뵫Ҫʱõģ簴ĸģ
//--------------------------------------------------------------------------------------------------
void		Direct3D_Update( HWND hwnd)
{
	//ʹDirectInputȡ
	g_pDInput->GetInput();

//ͨİAlphaֵı仯
	if (g_pDInput->IsKeyDown(DIK_1))  //1
	{
		for (DWORD i=0; i<g_dwNumMtrls; i++) 
		{
			g_pMaterials[i].Diffuse.a+= 0.001f;
		}
	}

	if (g_pDInput->IsKeyDown(DIK_2)) //1
	{
		for (DWORD i=0; i<g_dwNumMtrls; i++) 
		{
			g_pMaterials[i].Diffuse.a-= 0.001f;
		}
	}


	// ס϶ΪƽƲ
	static FLOAT fPosX = 0.0f, fPosY = -50.0f, fPosZ = 0.0f;
	
	if (g_pDInput->IsMouseButtonDown(0)) 
	{
		fPosX += (g_pDInput->MouseDX())*  0.08f;
		fPosY += (g_pDInput->MouseDY()) * -0.08f;
	}

	//֣Ϊ۲
	fPosZ += (g_pDInput->MouseDZ())* 0.02f;

	// ƽ
	if (g_pDInput->IsKeyDown(DIK_A)) fPosX -= 0.005f;
	if (g_pDInput->IsKeyDown(DIK_D)) fPosX += 0.005f;
	if (g_pDInput->IsKeyDown(DIK_W)) fPosY += 0.005f;
	if (g_pDInput->IsKeyDown(DIK_S)) fPosY -= 0.005f;


	D3DXMatrixTranslation(&g_matWorld, fPosX, fPosY, fPosZ);


	// סҼ϶Ϊת
	static float fAngleX = 0, fAngleY =0;
	
	if (g_pDInput->IsMouseButtonDown(1)) 
	{
		fAngleX += (g_pDInput->MouseDY())* -0.01f;
		fAngleY += (g_pDInput->MouseDX()) * -0.01f;
	}
	// ת
 	if (g_pDInput->IsKeyDown(DIK_UP)) fAngleX += 0.005f;
	if (g_pDInput->IsKeyDown(DIK_DOWN)) fAngleX -= 0.005f;
 	if (g_pDInput->IsKeyDown(DIK_LEFT)) fAngleY -= 0.005f;
 	if (g_pDInput->IsKeyDown(DIK_RIGHT)) fAngleY += 0.005f;


	D3DXMATRIX Rx, Ry;
	D3DXMatrixRotationX(&Rx, fAngleX);
	D3DXMatrixRotationY(&Ry, fAngleY);

	g_matWorld = Rx * Ry * g_matWorld;

	Matrix_Set();
}


//-----------------------------------Direct3D_Render( )-------------------------------
//	ʹDirect3DȾ
//--------------------------------------------------------------------------------------------------
void Direct3D_Render(HWND hwnd)
{

	//--------------------------------------------------------------------------------------
	// Direct3DȾ岽֮һ
	//--------------------------------------------------------------------------------------
	g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(160, 150, 150), 1.0f, 0);

	//һΣڻȡھ
	RECT formatRect;
	GetClientRect(hwnd, &formatRect);

	//--------------------------------------------------------------------------------------
	// Direct3DȾ岽֮ʼ
	//--------------------------------------------------------------------------------------
	g_pd3dDevice->BeginScene();                     // ʼ
	
	//--------------------------------------------------------------------------------------
	// Direct3DȾ岽֮ʽ
	//--------------------------------------------------------------------------------------


	//3Dģ
	g_pd3dDevice->SetTransform(D3DTS_WORLD, &g_matWorld);//ģ͵Ϊ׼
	// һforѭģ͵ֵĻ
	for (DWORD i = 0; i < g_dwNumMtrls; i++)
	{
		g_pd3dDevice->SetMaterial(&g_pMaterials[i]);  //ô˲ֵIJ
		g_pd3dDevice->SetTexture(0, g_pTextures[i]);//ô˲ֵ
		g_pMesh->DrawSubset(i);  //ƴ˲
	}

			//ڴϽǴʾÿ֡
			formatRect.top = 5;
			int charCount = swprintf_s(g_strFPS, 20, _T("FPS:%0.3f"), Get_FPS() );
			g_pTextFPS->DrawText(NULL, g_strFPS, charCount , &formatRect, DT_TOP | DT_RIGHT, D3DCOLOR_RGBA(0,239,136,255));

			//ʾԿ
			g_pTextAdaperName->DrawText(NULL,g_strAdapterName, -1, &formatRect, 
				DT_TOP | DT_LEFT, D3DXCOLOR(1.0f, 0.5f, 0.0f, 1.0f));

			// Ϣ
			 formatRect.top = 30;
			static wchar_t strInfo[256] = {0};
			swprintf_s(strInfo,-1, L"ģ: (%.2f, %.2f, %.2f)", g_matWorld._41, g_matWorld._42, g_matWorld._43);
			g_pTextHelper->DrawText(NULL, strInfo, -1, &formatRect, DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(135,239,136,255));

			// Ϣ
			formatRect.left = 0,formatRect.top = 380;
			g_pTextInfor->DrawText(NULL, L"˵:", -1, &formatRect, 
				DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(235,123,230,255));
			formatRect.top += 35;
			g_pTextHelper->DrawText(NULL, L"    ּ12СʵAlphaֵ", -1, &formatRect, 
				DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(255,200,0,255));
			formatRect.top += 25;
			g_pTextHelper->DrawText(NULL, L"    ס϶ƽģ", -1, &formatRect, 
				DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(255,200,0,255));
			formatRect.top += 25;
			g_pTextHelper->DrawText(NULL, L"    סҼ϶תģ", -1, &formatRect, 
				DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(255,200,0,255));
			formatRect.top += 25;
			g_pTextHelper->DrawText(NULL, L"    ֣ģ", -1, &formatRect, 
				DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(255,200,0,255));
			formatRect.top += 25;
			g_pTextHelper->DrawText(NULL, L"    WSADƽģ ", -1, &formatRect, 
				DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(255,200,0,255));
			formatRect.top += 25;
			g_pTextHelper->DrawText(NULL, L"    ϡ¡ҷתģ ", -1, &formatRect, 
				DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(255,200,0,255));
			formatRect.top += 25;
			g_pTextHelper->DrawText(NULL, L"    ESC : ˳", -1, &formatRect, 
				DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(255,200,0,255));

	//--------------------------------------------------------------------------------------
	// Direct3DȾ岽֮ġ
	//--------------------------------------------------------------------------------------
	g_pd3dDevice->EndScene();                       // 
	//--------------------------------------------------------------------------------------
	// Direct3DȾ岽֮塿ʾת
	//--------------------------------------------------------------------------------------
	g_pd3dDevice->Present(NULL, NULL, NULL, NULL);  // תʾ
	 
}




//-----------------------------------Get_FPS( )------------------------------------------
//	ڼÿ֡ʵһ
//--------------------------------------------------------------------------------------------------
float Get_FPS()
{

	//ĸ̬
	static float  fps = 0; //ҪFPSֵ
	static int    frameCount = 0;//֡
	static float  currentTime =0.0f;//ǰʱ
	static float  lastTime = 0.0f;//ʱ

	frameCount++;//ÿһGet_FPS()֡1
	currentTime = timeGetTime()*0.001f;//ȡϵͳʱ䣬timeGetTimeصԺΪλϵͳʱ䣬Ҫ0.001õλΪʱ

	//ǰʱȥʱ1ӣͽһFPSļͳʱĸ£ֵ֡
	if(currentTime - lastTime > 1.0f) //ʱ1
	{
		fps = (float)frameCount /(currentTime - lastTime);//1ӵFPSֵ
		lastTime = currentTime; //ǰʱcurrentTimeʱlastTimeΪһĻ׼ʱ
		frameCount    = 0;//֡frameCountֵ
	}

	return fps;
}


//-----------------------------------Direct3D_CleanUp( )--------------------------------
//	Direct3DԴͷCOMӿڶ
//---------------------------------------------------------------------------------------------------
void Direct3D_CleanUp()
{

	//ͷCOMӿڶ
	for (DWORD i = 0; i<g_dwNumMtrls; i++) 
		SAFE_RELEASE(g_pTextures[i]);

	SAFE_DELETE(g_pTextures); 
	SAFE_DELETE(g_pMaterials); 
	SAFE_DELETE(g_pDInput);
	SAFE_RELEASE(g_pMesh);
	SAFE_RELEASE(g_pd3dDevice);
	SAFE_RELEASE(g_pTextAdaperName)
	SAFE_RELEASE(g_pTextHelper)
	SAFE_RELEASE(g_pTextInfor)
	SAFE_RELEASE(g_pTextFPS)
	SAFE_RELEASE(g_pd3dDevice)
}

================================================
FILE: Direct3D-Game-Demo/D3Ddemo13/DirectInputClass.cpp
================================================
//=============================================================================
// Desc: DirectInput봦Դļ
// 2013 203  Create by dzī 
//=============================================================================
#include "DirectInputClass.h"


//-----------------------------------------------------------------------------
// Desc: 캯
//-----------------------------------------------------------------------------
DInputClass::DInputClass()
{
	m_pDirectInput = NULL;
	m_KeyboardDevice = NULL;
	ZeroMemory(m_keyBuffer,sizeof(char)*256);
	m_MouseDevice= NULL;
	ZeroMemory(&m_MouseState, sizeof(m_MouseState));
}


//-----------------------------------------------------------------------------
// NameDInputClass::Init(
// Desc: ʼDirectInput̼豸
//-----------------------------------------------------------------------------
HRESULT DInputClass::Init( HWND hWnd,HINSTANCE hInstance,DWORD keyboardCoopFlags, DWORD mouseCoopFlags )
{
	HRESULT hr;
	//ʼһIDirectInput8ӿڶ
	HR(DirectInput8Create( hInstance, DIRECTINPUT_VERSION, 
		IID_IDirectInput8,(void**)&m_pDirectInput,NULL ));

	//м豸ijʼ
	HR( m_pDirectInput->CreateDevice( GUID_SysKeyboard, &m_KeyboardDevice, NULL ));
	HR( m_KeyboardDevice->SetCooperativeLevel( hWnd, keyboardCoopFlags));
	HR( m_KeyboardDevice->SetDataFormat( &c_dfDIKeyboard ));
	HR( m_KeyboardDevice->Acquire( ));
	HR( m_KeyboardDevice->Poll( ));

	//豸ijʼ
	HR( m_pDirectInput->CreateDevice( GUID_SysMouse, &m_MouseDevice, NULL ));
	HR( m_MouseDevice->SetCooperativeLevel( hWnd,mouseCoopFlags));
	HR( m_MouseDevice->SetDataFormat( &c_dfDIMouse ));
	HR( m_MouseDevice->Acquire( ));
	HR( m_KeyboardDevice->Poll( ));

	return S_OK;
}


//-----------------------------------------------------------------------------
// NameDInputClass::GetInput()
// Desc: ڻȡϢĺ
//-----------------------------------------------------------------------------
void DInputClass::GetInput()
{
	HRESULT hr = m_KeyboardDevice->GetDeviceState(sizeof(m_keyBuffer), (void**)&m_keyBuffer); 
	//ȡϢ
	if(hr)
	{
		m_KeyboardDevice->Acquire();  
		m_KeyboardDevice->GetDeviceState( sizeof(m_keyBuffer),(LPVOID)m_keyBuffer );
	}

	hr = m_MouseDevice->GetDeviceState(sizeof(DIMOUSESTATE), (void**)&m_MouseState); 
	//ȡϢ
	if(hr)
	{
		m_MouseDevice->Acquire();
		m_MouseDevice->GetDeviceState( sizeof(DIMOUSESTATE), (void**)&m_MouseState);
	}
}

//-----------------------------------------------------------------------------
// NameDInputClass::IsKeyDown()
// Desc: жϼijǷ
//-----------------------------------------------------------------------------
bool DInputClass::IsKeyDown(int iKey)
{
	if(m_keyBuffer[iKey] & 0x80)
		return true;
	else
		return false;
}


//-----------------------------------------------------------------------------
// NameDInputClass::IsMouseButtonDown()
// Desc: жijǷ
//-----------------------------------------------------------------------------
bool DInputClass::IsMouseButtonDown(int button)
{
	return (m_MouseState.rgbButtons[button] & 0x80) != 0;
}

//-----------------------------------------------------------------------------
// NameDInputClass::MouseDX
// Desc: ָXֵ
//-----------------------------------------------------------------------------
float DInputClass::MouseDX()
{
	return (float)m_MouseState.lX;
}

//-----------------------------------------------------------------------------
// NameDInputClass::MouseDY
// Desc: ָYֵ
//-----------------------------------------------------------------------------
float DInputClass::MouseDY()
{
	return (float)m_MouseState.lY;
}

//-----------------------------------------------------------------------------
// NameDInputClass::MouseDZ
// Desc: ָZֵ֣
//-----------------------------------------------------------------------------
float DInputClass::MouseDZ()
{
	return (float)m_MouseState.lZ;
}




//-----------------------------------------------------------------------------
// Desc: 
//-----------------------------------------------------------------------------
DInputClass::~DInputClass(void)
{
	if(m_KeyboardDevice != NULL)
		m_KeyboardDevice->Unacquire();
	if(m_MouseDevice != NULL)
		m_MouseDevice->Unacquire();
	SAFE_RELEASE(m_KeyboardDevice);
	SAFE_RELEASE(m_MouseDevice);
	SAFE_RELEASE(m_pDirectInput);
}


================================================
FILE: Direct3D-Game-Demo/D3Ddemo13/DirectInputClass.h
================================================
//=============================================================================
// Name: DirectInputClass.h
//	Des: װDirectInput봦ͷļ
// 2013 203  Create by dzī 
//=============================================================================
#pragma once
#include "D3DUtil.h"
#define DIRECTINPUT_VERSION 0x0800
#include <dinput.h>

//DInputClassඨ忪ʼ
class DInputClass
{
private:
	IDirectInput8					* m_pDirectInput;   //IDirectInput8ӿڶ
	IDirectInputDevice8		* m_KeyboardDevice;  //豸ӿڶ
	char								m_keyBuffer[256];       //ڼֵ̼洢

	IDirectInputDevice8		*m_MouseDevice;      //豸ӿڶ
	DIMOUSESTATE				m_MouseState;			//ֵ洢һṹ

public:
	HRESULT		Init( HWND hWnd,HINSTANCE hInstance,DWORD keyboardCoopFlags, DWORD mouseCoopFlags ); //ʼDirectInput̼豸
	void				GetInput();   //ڻȡϢĺ
	bool				IsKeyDown(int iKey);   //жϼijǷ
	
	bool				IsMouseButtonDown(int button);  //ж갴Ƿ񱻰
	float				MouseDX();   //Xֵ
	float				MouseDY();	//Yֵ
	float				MouseDZ();	//Zֵ


public:
	DInputClass(void);		//캯
	~DInputClass(void);	//
};


================================================
FILE: Direct3D-Game-Demo/D3Ddemo14/D3DUtil.h
================================================

//*****************************************************************************************
// Desc: D3DUtil.hͷļڹĶ
// 2013 203  Create by dzī 
//*****************************************************************************************

#pragma once


#ifndef HR
#define HR(x)    { hr = x; if( FAILED(hr) ) { return hr; } }         //ԶһHRִ꣬дķ
#endif

#ifndef SAFE_DELETE					
#define SAFE_DELETE(p)       { if(p) { delete (p);     (p)=NULL; } }       //ԶһSAFE_RELEASE(),ָԴͷ
#endif    

#ifndef SAFE_RELEASE			
#define SAFE_RELEASE(p)      { if(p) { (p)->Release(); (p)=NULL; } }     //ԶһSAFE_RELEASE(),COMԴͷ
#endif

================================================
FILE: Direct3D-Game-Demo/D3Ddemo14/D3Ddemo14.cpp
================================================
//-----------------------------------˵----------------------------------------------
//  :D3Ddemo13
//	 20134 Create by dzī
//  ˮ齻ڵalphaϼ ʾ
//------------------------------------------------------------------------------------------------


//-----------------------------------궨岿֡--------------------------------------------
// һЩ
//------------------------------------------------------------------------------------------------
#define WINDOW_WIDTH	800						//Ϊڿȶĺ꣬Էڴ˴޸Ĵڿ
#define WINDOW_HEIGHT	600							//Ϊڸ߶ȶĺ꣬Էڴ˴޸Ĵڸ߶
#define WINDOW_TITLE	_T("ϨϷ롿  ȲZ ʾ") //Ϊڱⶨĺ



//-----------------------------------ͷļ֡---------------------------------------
//	ͷļ
//------------------------------------------------------------------------------------------------                                                                             
#include <d3d9.h>
#include <d3dx9.h>
#include <tchar.h>
#include <time.h> 
#include "DirectInputClass.h"


//-----------------------------------ļ֡---------------------------------------
//	Ŀļ
//------------------------------------------------------------------------------------------------
#pragma comment(lib,"d3d9.lib")
#pragma comment(lib,"d3dx9.lib")
#pragma comment(lib, "dinput8.lib")     // ʹDirectInputĿļע8
#pragma comment(lib,"dxguid.lib")
#pragma comment(lib, "winmm.lib") 



//-----------------------------------ȫֱ֡-------------------------------------
//	ȫֱ
//------------------------------------------------------------------------------------------------
LPDIRECT3DDEVICE9					g_pd3dDevice = NULL; //Direct3D豸
LPD3DXFONT								g_pTextFPS				=NULL;    //COMӿ
LPD3DXFONT								g_pTextAdaperName           = NULL;  // ԿϢ2Dı
LPD3DXFONT								g_pTextHelper          = NULL;  // Ϣ2Dı
LPD3DXFONT								g_pTextInfor           = NULL;  // Ϣ2Dı
float											g_FPS								= 0.0f;       //һ͵ı֡
wchar_t										g_strFPS[50]={0};    //֡ʵַ
wchar_t										g_strAdapterName[60]={0};    //ԿƵַ
D3DXMATRIX							g_matWorld;   //
DInputClass*								g_pDInput = NULL;         //һDInputClassָ

LPD3DXMESH          g_pMesh     = NULL; // 
D3DMATERIAL9*       g_pMaterials    = NULL; // IJϢ
LPDIRECT3DTEXTURE9* g_pTextures     = NULL; // Ϣ
DWORD               g_dwNumMtrls    = 0;    // ʵĿ

LPD3DXMESH          g_pMeshWall     = NULL; // ǽ
D3DMATERIAL9        g_MaterialsWall;  // 


//-----------------------------------ȫֺ֡-------------------------------------
//	ȫֺֹδıʶϵд
//------------------------------------------------------------------------------------------------
LRESULT CALLBACK		WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam );
HRESULT						Direct3D_Init(HWND hwnd,HINSTANCE hInstance);
HRESULT						Objects_Init();
void								Direct3D_Render( HWND hwnd);
void								Direct3D_Update( HWND hwnd);
void								Direct3D_CleanUp( );
float								Get_FPS();
void								Matrix_Set();


//-----------------------------------WinMain( )--------------------------------------
//	WindowsӦóںǵij↑ʼ
//------------------------------------------------------------------------------------------------
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nShowCmd)
{

	//ʼһĴ
	WNDCLASSEX wndClass = { 0 };				//WINDCLASSEXһ࣬wndClassʵWINDCLASSEX֮󴰿ڵĸʼ    
	wndClass.cbSize = sizeof( WNDCLASSEX ) ;	//ýṹֽС
	wndClass.style = CS_HREDRAW | CS_VREDRAW;	//ôڵʽ
	wndClass.lpfnWndProc = WndProc;				//ָ򴰿ڹָ̺
	wndClass.cbClsExtra		= 0;
	wndClass.cbWndExtra		= 0;
	wndClass.hInstance = hInstance;				//ָڹ̵ijʵ
	wndClass.hIcon=(HICON)::LoadImage(NULL,_T("icon.ico"),IMAGE_ICON,0,0,LR_DEFAULTSIZE|LR_LOADFROMFILE); //ȫֵ::LoadImageӱؼԶicoͼ
	wndClass.hCursor = LoadCursor( NULL, IDC_ARROW );    //ָĹ
	wndClass.hbrBackground=(HBRUSH)GetStockObject(GRAY_BRUSH);  //ΪhbrBackgroundԱָһɫˢ
	wndClass.lpszMenuName = NULL;						//һԿַָֹ˵Դ֡
	wndClass.lpszClassName = _T("ForTheDreamOfGameDevelop");		//һԿַָֹ֡

	if( !RegisterClassEx( &wndClass ) )				//괰ںҪԴעᣬܴ͵Ĵ
		return -1;		

	HWND hwnd = CreateWindow( _T("ForTheDreamOfGameDevelop"),WINDOW_TITLE,			//ϲּĴںCreateWindow
		WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, WINDOW_WIDTH,
		WINDOW_HEIGHT, NULL, NULL, hInstance, NULL );


	//Direct3DԴijʼʧmessageboxʾ
	if (!(S_OK==Direct3D_Init (hwnd,hInstance)))
	{
		MessageBox(hwnd, _T("Direct3Dʼʧ~"), _T("dzīϢ"), 0); //ʹMessageBoxһϢ 
	}
	PlaySound(L"A Watchful Guardian.wav", NULL, SND_FILENAME | SND_ASYNC|SND_LOOP);   //ѭű

	

	MoveWindow(hwnd,200,50,WINDOW_WIDTH,WINDOW_HEIGHT,true);   //ʾʱλãϽλĻ꣨20050
	ShowWindow( hwnd, nShowCmd );    //Win32ShowWindowʾ
	UpdateWindow(hwnd);  //Դڽи£·Ҫװһ

	//DirectInputijʼ
	g_pDInput = new DInputClass();
	g_pDInput->Init(hwnd,hInstance,DISCL_FOREGROUND | DISCL_NONEXCLUSIVE,DISCL_FOREGROUND | DISCL_NONEXCLUSIVE);

	//Ϣѭ
	MSG msg = { 0 };  //ʼmsg
	while( msg.message != WM_QUIT )			//ʹwhileѭ
	{
		if( PeekMessage( &msg, 0, 0, 0, PM_REMOVE ) )   //鿴ӦóϢУϢʱеϢɷȥ
		{
			TranslateMessage( &msg );		//ϢתΪַϢ
			DispatchMessage( &msg );		//úַһϢڳ
		}
		else
		{
			Direct3D_Update(hwnd);         //øºлĸ
			Direct3D_Render(hwnd);			//ȾлȾ			
		}
	}

	UnregisterClass(_T("ForTheDreamOfGameDevelop"), wndClass.hInstance);
	return 0;  
}

//-----------------------------------WndProc( )--------------------------------------
//	ڹ̺WndProc,ԴϢд
//------------------------------------------------------------------------------------------------
LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )   //ڹ̺WndProc
{
	switch( message )				//switch俪ʼ
	{
	case WM_PAINT:					 // ͻػϢ
		Direct3D_Render(hwnd);          //Direct3D_RenderлĻ
		ValidateRect(hwnd, NULL);   // ¿ͻʾ
		break;									//switch

	case WM_KEYDOWN:                // ̰Ϣ
		if (wParam == VK_ESCAPE)    // ESC
			DestroyWindow(hwnd);    // ٴ, һWM_DESTROYϢ
		break;
	case WM_DESTROY:				//Ϣ
		Direct3D_CleanUp();     //Direct3D_CleanUpCOMӿڶ
		PostQuitMessage( 0 );		//ϵͳиֹ߳ӦWM_DESTROYϢ
		break;						//switch

	default:						//caseϣִиdefault
		return DefWindowProc( hwnd, message, wParam, lParam );		//ȱʡĴڹΪӦóûдĴϢṩȱʡĴ
	}

	return 0;					//˳
}


//-----------------------------------Direct3D_Init( )----------------------------------
//	Direct3DʼDirect3Dijʼ
//------------------------------------------------------------------------------------------------
HRESULT Direct3D_Init(HWND hwnd,HINSTANCE hInstance)
{

	//--------------------------------------------------------------------------------------
	// Direct3DʼIJ֮һӿڡDirect3Dӿڶ, ԱøDirect3D󴴽Direct3D豸
	//--------------------------------------------------------------------------------------
	LPDIRECT3D9  pD3D = NULL; //Direct3DӿڶĴ
	if( NULL == ( pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) ) //ʼDirect3Dӿڶ󣬲DirectX汾Э
 			return E_FAIL;

	//--------------------------------------------------------------------------------------
	// Direct3DʼIJ֮,ȡϢȡӲ豸Ϣ
	//--------------------------------------------------------------------------------------
	D3DCAPS9 caps; int vp = 0;
	if( FAILED( pD3D->GetDeviceCaps( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &caps ) ) )
		{
			return E_FAIL;
		}
	if( caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT )
		vp = D3DCREATE_HARDWARE_VERTEXPROCESSING;   //֧Ӳ㣬ǾͲӲ㣬׵
	else
		vp = D3DCREATE_SOFTWARE_VERTEXPROCESSING; //֧Ӳ㣬ֻò

	//--------------------------------------------------------------------------------------
	// Direct3DʼIJ֮ݡD3DPRESENT_PARAMETERSṹ
	//--------------------------------------------------------------------------------------
	D3DPRESENT_PARAMETERS d3dpp; 
	ZeroMemory(&d3dpp, sizeof(d3dpp));
	d3dpp.BackBufferWidth            = WINDOW_WIDTH;
	d3dpp.BackBufferHeight           = WINDOW_HEIGHT;
	d3dpp.BackBufferFormat           = D3DFMT_A8R8G8B8;
	d3dpp.BackBufferCount            = 2;
	d3dpp.MultiSampleType            = D3DMULTISAMPLE_NONE;
	d3dpp.MultiSampleQuality         = 0;
	d3dpp.SwapEffect                 = D3DSWAPEFFECT_DISCARD; 
	d3dpp.hDeviceWindow              = hwnd;
	d3dpp.Windowed                   = true;
	d3dpp.EnableAutoDepthStencil     = true; 
	d3dpp.AutoDepthStencilFormat     = D3DFMT_D24S8;
	d3dpp.Flags                      = 0;
	d3dpp.FullScreen_RefreshRateInHz = 0;
	d3dpp.PresentationInterval       = D3DPRESENT_INTERVAL_IMMEDIATE;

	//--------------------------------------------------------------------------------------
	// Direct3DʼIJ֮ģ豸Direct3D豸ӿ
	//--------------------------------------------------------------------------------------
	if(FAILED(pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, 
		hwnd, vp, &d3dpp, &g_pd3dDevice)))
		return E_FAIL;


	//ȡԿϢg_strAdapterNameУԿ֮ǰϡǰԿͺţַ
	 wchar_t TempName[60]=L"ǰԿͺţ";   //һʱַҷ˰"ǰԿͺţ"ַǵĿַ
	 D3DADAPTER_IDENTIFIER9 Adapter;  //һD3DADAPTER_IDENTIFIER9ṹ壬ڴ洢ԿϢ
	 pD3D->GetAdapterIdentifier(0,0,&Adapter);//GetAdapterIdentifierȡԿϢ
	 int len = MultiByteToWideChar(CP_ACP,0, Adapter.Description, -1, NULL, 0);//ԿѾAdapter.DescriptionˣΪcharͣҪתΪwchar_t
	 MultiByteToWideChar(CP_ACP, 0, Adapter.Description, -1, g_strAdapterName, len);//ⲽɺg_strAdapterNameоΪǰǵԿwchar_tַ
	 wcscat_s(TempName,g_strAdapterName);//ѵǰǵԿӵǰԿͺţַ棬TempName
	 wcscpy_s(g_strAdapterName,TempName);//TempNameеĽȫֱg_strAdapterNameУ󹦸~

	if(!(S_OK==Objects_Init())) return E_FAIL;

	SAFE_RELEASE(pD3D) //LPDIRECT3D9ӿڶʹɣǽͷŵ

	return S_OK;
}

//-----------------------------------Object_Init( )--------------------------------------
//	ȾԴʼڴ˺нҪȾԴijʼ
//--------------------------------------------------------------------------------------------------
HRESULT Objects_Init()
{
	//
	D3DXCreateFont(g_pd3dDevice, 36, 0, 0, 1000, false, DEFAULT_CHARSET, 
		OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, 0, _T("Calibri"), &g_pTextFPS);
	D3DXCreateFont(g_pd3dDevice, 20, 0, 1000, 0, false, DEFAULT_CHARSET, 
		OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, 0, L"", &g_pTextAdaperName); 
	D3DXCreateFont(g_pd3dDevice, 23, 0, 1000, 0, false, DEFAULT_CHARSET, 
		OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, 0, L"΢ź", &g_pTextHelper); 
	D3DXCreateFont(g_pd3dDevice, 26, 0, 1000, 0, false, DEFAULT_CHARSET, 
		OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, 0, L"", &g_pTextInfor); 


	// Xļм
	LPD3DXBUFFER pAdjBuffer  = NULL;
	LPD3DXBUFFER pMtrlBuffer = NULL;

	D3DXLoadMeshFromX(L"SwordMan.X", D3DXMESH_MANAGED, g_pd3dDevice, 
		&pAdjBuffer, &pMtrlBuffer, NULL, &g_dwNumMtrls, &g_pMesh);

	// ȡʺ
	D3DXMATERIAL *pMtrls = (D3DXMATERIAL*)pMtrlBuffer->GetBufferPointer(); //һD3DXMATERIALṹڶȡʺϢ
	g_pMaterials = new D3DMATERIAL9[g_dwNumMtrls];
	g_pTextures  = new LPDIRECT3DTEXTURE9[g_dwNumMtrls];

	for (DWORD i=0; i<g_dwNumMtrls; i++) 
	{
		//ȡʣһ»ɫֵ
		g_pMaterials[i] = pMtrls[i].MatD3D;
		g_pMaterials[i].Ambient = g_pMaterials[i].Diffuse;

		//һ
		g_pTextures[i]  = NULL;
		D3DXCreateTextureFromFileA(g_pd3dDevice, pMtrls[i].pTextureFilename, &g_pTextures[i]);
	}

	SAFE_RELEASE(pAdjBuffer)
	SAFE_RELEASE(pMtrlBuffer)


	//D3DXCreateBoxһ
	D3DXCreateBox(g_pd3dDevice, 30.0f, 30.0f, 0.5f, &g_pMeshWall, NULL);
	g_MaterialsWall.Ambient  = D3DXCOLOR(0.8f, 0.2f, 0.1f, 1.0f);
	g_MaterialsWall.Diffuse  = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	g_MaterialsWall.Specular = D3DXCOLOR(0.1f, 0.1f, 0.1f, 1.0f);

	// ù
	D3DLIGHT9 light;
	::ZeroMemory(&light, sizeof(light));
	light.Type          = D3DLIGHT_DIRECTIONAL;
	light.Ambient       = D3DXCOLOR(0.5f, 0.5f, 0.5f, 1.0f);
	light.Diffuse       = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	light.Specular      = D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f);
	light.Direction     = D3DXVECTOR3(1.0f, 0.0f, 1.0f);
	g_pd3dDevice->SetLight(0, &light);
	g_pd3dDevice->LightEnable(0, true);
	g_pd3dDevice->SetRenderState(D3DRS_NORMALIZENORMALS, true);
	g_pd3dDevice->SetRenderState(D3DRS_SPECULARENABLE, true);

	// Ⱦ״̬
	g_pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);   //
	g_pd3dDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESS);   //ȲԺΪD3DCMP_LESS
	g_pd3dDevice->SetRenderState(D3DRS_ZWRITEENABLE, true);     //ȲԳɹ󣬸Ȼ

	return S_OK;
}


//-----------------------------------Matrix_Set( )--------------------------------------
//	װDirect3DĴ任ĺ任ȡ任ͶӰ任ӿڱ任
//--------------------------------------------------------------------------------------------------
void Matrix_Set()
{

	//--------------------------------------------------------------------------------------
	//Ĵ任֮ȡ任
	//--------------------------------------------------------------------------------------
	D3DXMATRIX matView; //һ
	D3DXVECTOR3 vEye(0.0f, 0.0f, -150.0f);  //λ
	D3DXVECTOR3 vAt(0.0f, 0.0f, 0.0f); //۲λ
	D3DXVECTOR3 vUp(0.0f, 1.0f, 0.0f);//ϵ
	D3DXMatrixLookAtLH(&matView, &vEye, &vAt, &vUp); //ȡ任
	g_pd3dDevice->SetTransform(D3DTS_VIEW, &matView); //Ӧȡ任

	//--------------------------------------------------------------------------------------
	//Ĵ任֮ͶӰ任
	//--------------------------------------------------------------------------------------
	D3DXMATRIX matProj; //һ
	D3DXMatrixPerspectiveFovLH(&matProj, D3DX_PI / 4.0f,(float)((double)WINDOW_WIDTH/WINDOW_HEIGHT),1.0f, 1000.0f); //ͶӰ任
	g_pd3dDevice->SetTransform(D3DTS_PROJECTION, &matProj);  //ͶӰ任

	//--------------------------------------------------------------------------------------
	//Ĵ任֮ġӿڱ任
	//--------------------------------------------------------------------------------------
	D3DVIEWPORT9 vp; //ʵһD3DVIEWPORT9ṹ壬ȻֵͿ
	vp.X      = 0;		//ʾӿڴڵX
	vp.Y      = 0;		//ӿԶԴڵY
	vp.Width  = WINDOW_WIDTH;	//ӿڵĿ
	vp.Height = WINDOW_HEIGHT; //ӿڵĸ߶
	vp.MinZ   = 0.0f; //ӿȻеСֵ
	vp.MaxZ   = 1.0f;	//ӿȻеֵ
	g_pd3dDevice->SetViewport(&vp); //ӿڵ

}

//-----------------------------------Direct3D_Update( )--------------------------------
//	ǼʱȾ뵫Ҫʱõģ簴ĸģ
//--------------------------------------------------------------------------------------------------
void	Direct3D_Update( HWND hwnd)
{
	//ʹDirectInputȡ
	g_pDInput->GetInput();

	// ߹رȲ
	if (g_pDInput->IsKeyDown(DIK_1))  //1Ȳ
		g_pd3dDevice->SetRenderState(D3DRS_ZENABLE, true);
	if (g_pDInput->IsKeyDown(DIK_2))  //2رȲ
		g_pd3dDevice->SetRenderState(D3DRS_ZENABLE, false);


	// ס϶ΪƽƲ
	static FLOAT fPosX = 0.0f, fPosY = -50.0f, fPosZ = 0.0f;
	
	if (g_pDInput->IsMouseButtonDown(0)) 
	{
		fPosX += (g_pDInput->MouseDX())*  0.08f;
		fPosY += (g_pDInput->MouseDY()) * -0.08f;
	}

	//֣Ϊ۲
	fPosZ += (g_pDInput->MouseDZ())* 0.02f;

	// ƽ
	if (g_pDInput->IsKeyDown(DIK_A)) fPosX -= 0.005f;
	if (g_pDInput->IsKeyDown(DIK_D)) fPosX += 0.005f;
	if (g_pDInput->IsKeyDown(DIK_W)) fPosY += 0.005f;
	if (g_pDInput->IsKeyDown(DIK_S)) fPosY -= 0.005f;


	D3DXMatrixTranslation(&g_matWorld, fPosX, fPosY, fPosZ);


	// סҼ϶Ϊת
	static float fAngleX = 0, fAngleY =0;
	
	if (g_pDInput->IsMouseButtonDown(1)) 
	{
		fAngleX += (g_pDInput->MouseDY())* -0.01f;
		fAngleY += (g_pDInput->MouseDX()) * -0.01f;
	}
	// ת
 	if (g_pDInput->IsKeyDown(DIK_UP)) fAngleX += 0.005f;
	if (g_pDInput->IsKeyDown(DIK_DOWN)) fAngleX -= 0.005f;
 	if (g_pDInput->IsKeyDown(DIK_LEFT)) fAngleY -= 0.005f;
 	if (g_pDInput->IsKeyDown(DIK_RIGHT)) fAngleY += 0.005f;


	D3DXMATRIX Rx, Ry;
	D3DXMatrixRotationX(&Rx, fAngleX);
	D3DXMatrixRotationY(&Ry, fAngleY);

	g_matWorld = Rx * Ry * g_matWorld;

	Matrix_Set();
}


//-----------------------------------Direct3D_Render( )-------------------------------
//	ʹDirect3DȾ
//--------------------------------------------------------------------------------------------------
void Direct3D_Render(HWND hwnd)
{

	//--------------------------------------------------------------------------------------
	// Direct3DȾ岽֮һ
	//--------------------------------------------------------------------------------------
	g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(160, 100, 150), 1.0f, 0);

	//һΣڻȡھ
	RECT formatRect;
	GetClientRect(hwnd, &formatRect);

	//--------------------------------------------------------------------------------------
	// Direct3DȾ岽֮ʼ
	//--------------------------------------------------------------------------------------
	g_pd3dDevice->BeginScene();                     // ʼ
	
	//--------------------------------------------------------------------------------------
	// Direct3DȾ岽֮ʽ
	//--------------------------------------------------------------------------------------


	//3Dģ
	g_pd3dDevice->SetTransform(D3DTS_WORLD, &g_matWorld);//ģ͵Ϊ׼
	// һforѭģ͵ֵĻ
	for (DWORD i = 0; i < g_dwNumMtrls; i++)
	{
		g_pd3dDevice->SetMaterial(&g_pMaterials[i]);  //ô˲ֵIJ
		g_pd3dDevice->SetTexture(0, g_pTextures[i]);//ô˲ֵ
		g_pMesh->DrawSubset(i);  //ƴ˲
	}

	// ǽ
	D3DXMATRIX matWorld;   //һΪ׼Ϊǽ	
	D3DXMatrixTranslation(&matWorld, 0.0f,0.0f,-50.0f);//ǽʼZΪ-50.0f
	g_pd3dDevice->SetTransform(D3DTS_WORLD, &matWorld);//ǽ
	g_pd3dDevice->SetMaterial(&g_MaterialsWall);//ò
	g_pMeshWall->DrawSubset(0); //ǽ


			//ڴϽǴʾÿ֡
			formatRect.top = 5;
			int charCount = swprintf_s(g_strFPS, 20, _T("FPS:%0.3f"), Get_FPS() );
			g_pTextFPS->DrawText(NULL, g_strFPS, charCount , &formatRect, DT_TOP | DT_RIGHT, D3DCOLOR_RGBA(0,239,136,255));

			//ʾԿ
			g_pTextAdaperName->DrawText(NULL,g_strAdapterName, -1, &formatRect, 
				DT_TOP | DT_LEFT, D3DXCOLOR(1.0f, 0.5f, 0.0f, 1.0f));

			// Ϣ
			 formatRect.top = 30;
			static wchar_t strInfo[256] = {0};
			swprintf_s(strInfo,-1, L"ģ: (%.2f, %.2f, %.2f)", g_matWorld._41, g_matWorld._42, g_matWorld._43);
			g_pTextHelper->DrawText(NULL, strInfo, -1, &formatRect, DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(135,239,136,255));

			// Ϣ
			formatRect.left = 0,formatRect.top = 380;
			g_pTextInfor->DrawText(NULL, L"˵:", -1, &formatRect, 
				DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(235,123,230,255));
			formatRect.top += 35;
			g_pTextHelper->DrawText(NULL, L"    ּ12߹رȲ", -1, &formatRect, 
				DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(255,200,0,255));
			formatRect.top += 25;
			g_pTextHelper->DrawText(NULL, L"    ס϶ƽģ", -1, &formatRect, 
				DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(255,200,0,255));
			formatRect.top += 25;
			g_pTextHelper->DrawText(NULL, L"    סҼ϶תģ", -1, &formatRect, 
				DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(255,200,0,255));
			formatRect.top += 25;
			g_pTextHelper->DrawText(NULL, L"    ֣ģ", -1, &formatRect, 
				DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(255,200,0,255));
			formatRect.top += 25;
			g_pTextHelper->DrawText(NULL, L"    WSADƽģ ", -1, &formatRect, 
				DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(255,200,0,255));
			formatRect.top += 25;
			g_pTextHelper->DrawText(NULL, L"    ϡ¡ҷתģ ", -1, &formatRect, 
				DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(255,200,0,255));
			formatRect.top += 25;
			g_pTextHelper->DrawText(NULL, L"    ESC : ˳", -1, &formatRect, 
				DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(255,200,0,255));


	//--------------------------------------------------------------------------------------
	// Direct3DȾ岽֮ġ
	//--------------------------------------------------------------------------------------
	g_pd3dDevice->EndScene();                       // 
	//--------------------------------------------------------------------------------------
	// Direct3DȾ岽֮塿ʾת
	//--------------------------------------------------------------------------------------
	g_pd3dDevice->Present(NULL, NULL, NULL, NULL);  // תʾ
	 
}


//-----------------------------------Get_FPS( )------------------------------------------
//	ڼÿ֡ʵһ
//--------------------------------------------------------------------------------------------------
float Get_FPS()
{

	//ĸ̬
	static float  fps = 0; //ҪFPSֵ
	static int    frameCount = 0;//֡
	static float  currentTime =0.0f;//ǰʱ
	static float  lastTime = 0.0f;//ʱ

	frameCount++;//ÿһGet_FPS()֡1
	currentTime = timeGetTime()*0.001f;//ȡϵͳʱ䣬timeGetTimeصԺΪλϵͳʱ䣬Ҫ0.001õλΪʱ

	//ǰʱȥʱ1ӣͽһFPSļͳʱĸ£ֵ֡
	if(currentTime - lastTime > 1.0f) //ʱ1
	{
		fps = (float)frameCount /(currentTime - lastTime);//1ӵFPSֵ
		lastTime = currentTime; //ǰʱcurrentTimeʱlastTimeΪһĻ׼ʱ
		frameCount    = 0;//֡frameCountֵ
	}

	return fps;
}


//-----------------------------------Direct3D_CleanUp( )--------------------------------
//	Direct3DԴͷCOMӿڶ
//---------------------------------------------------------------------------------------------------
void Direct3D_CleanUp()
{

	//ͷCOMӿڶ
	for (DWORD i = 0; i<g_dwNumMtrls; i++) 
		SAFE_RELEASE(g_pTextures[i]);

	SAFE_DELETE(g_pTextures); 
	SAFE_DELETE(g_pMaterials); 
	SAFE_DELETE(g_pDInput);
	SAFE_RELEASE(g_pMeshWall);
	SAFE_RELEASE(g_pMesh);
	SAFE_RELEASE(g_pd3dDevice);
	SAFE_RELEASE(g_pTextAdaperName)
	SAFE_RELEASE(g_pTextHelper)
	SAFE_RELEASE(g_pTextInfor)
	SAFE_RELEASE(g_pTextFPS)
	SAFE_RELEASE(g_pd3dDevice)
}

================================================
FILE: Direct3D-Game-Demo/D3Ddemo14/DirectInputClass.cpp
================================================
//=============================================================================
// Desc: DirectInput봦Դļ
// 2013 203  Create by dzī 
//=============================================================================
#include "DirectInputClass.h"


//-----------------------------------------------------------------------------
// Desc: 캯
//-----------------------------------------------------------------------------
DInputClass::DInputClass()
{
	m_pDirectInput = NULL;
	m_KeyboardDevice = NULL;
	ZeroMemory(m_keyBuffer,sizeof(char)*256);
	m_MouseDevice= NULL;
	ZeroMemory(&m_MouseState, sizeof(m_MouseState));
}


//-----------------------------------------------------------------------------
// NameDInputClass::Init(
// Desc: ʼDirectInput̼豸
//-----------------------------------------------------------------------------
HRESULT DInputClass::Init( HWND hWnd,HINSTANCE hInstance,DWORD keyboardCoopFlags, DWORD mouseCoopFlags )
{
	HRESULT hr;
	//ʼһIDirectInput8ӿڶ
	HR(DirectInput8Create( hInstance, DIRECTINPUT_VERSION, 
		IID_IDirectInput8,(void**)&m_pDirectInput,NULL ));

	//м豸ijʼ
	HR( m_pDirectInput->CreateDevice( GUID_SysKeyboard, &m_KeyboardDevice, NULL ));
	HR( m_KeyboardDevice->SetCooperativeLevel( hWnd, keyboardCoopFlags));
	HR( m_KeyboardDevice->SetDataFormat( &c_dfDIKeyboard ));
	HR( m_KeyboardDevice->Acquire( ));
	HR( m_KeyboardDevice->Poll( ));

	//豸ijʼ
	HR( m_pDirectInput->CreateDevice( GUID_SysMouse, &m_MouseDevice, NULL ));
	HR( m_MouseDevice->SetCooperativeLevel( hWnd,mouseCoopFlags));
	HR( m_MouseDevice->SetDataFormat( &c_dfDIMouse ));
	HR( m_MouseDevice->Acquire( ));
	HR( m_KeyboardDevice->Poll( ));

	return S_OK;
}


//-----------------------------------------------------------------------------
// NameDInputClass::GetInput()
// Desc: ڻȡϢĺ
//-----------------------------------------------------------------------------
void DInputClass::GetInput()
{
	HRESULT hr = m_KeyboardDevice->GetDeviceState(sizeof(m_keyBuffer), (void**)&m_keyBuffer); 
	//ȡϢ
	if(hr)
	{
		m_KeyboardDevice->Acquire();  
		m_KeyboardDevice->GetDeviceState( sizeof(m_keyBuffer),(LPVOID)m_keyBuffer );
	}

	hr = m_MouseDevice->GetDeviceState(sizeof(DIMOUSESTATE), (void**)&m_MouseState); 
	//ȡϢ
	if(hr)
	{
		m_MouseDevice->Acquire();
		m_MouseDevice->GetDeviceState( sizeof(DIMOUSESTATE), (void**)&m_MouseState);
	}
}

//-----------------------------------------------------------------------------
// NameDInputClass::IsKeyDown()
// Desc: жϼijǷ
//-----------------------------------------------------------------------------
bool DInputClass::IsKeyDown(int iKey)
{
	if(m_keyBuffer[iKey] & 0x80)
		return true;
	else
		return false;
}


//-----------------------------------------------------------------------------
// NameDInputClass::IsMouseButtonDown()
// Desc: жijǷ
//-----------------------------------------------------------------------------
bool DInputClass::IsMouseButtonDown(int button)
{
	return (m_MouseState.rgbButtons[button] & 0x80) != 0;
}

//-----------------------------------------------------------------------------
// NameDInputClass::MouseDX
// Desc: ָXֵ
//-----------------------------------------------------------------------------
float DInputClass::MouseDX()
{
	return (float)m_MouseState.lX;
}

//-----------------------------------------------------------------------------
// NameDInputClass::MouseDY
// Desc: ָYֵ
//-----------------------------------------------------------------------------
float DInputClass::MouseDY()
{
	return (float)m_MouseState.lY;
}

//-----------------------------------------------------------------------------
// NameDInputClass::MouseDZ
// Desc: ָZֵ֣
//-----------------------------------------------------------------------------
float DInputClass::MouseDZ()
{
	return (float)m_MouseState.lZ;
}




//-----------------------------------------------------------------------------
// Desc: 
//-----------------------------------------------------------------------------
DInputClass::~DInputClass(void)
{
	if(m_KeyboardDevice != NULL)
		m_KeyboardDevice->Unacquire();
	if(m_MouseDevice != NULL)
		m_MouseDevice->Unacquire();
	SAFE_RELEASE(m_KeyboardDevice);
	SAFE_RELEASE(m_MouseDevice);
	SAFE_RELEASE(m_pDirectInput);
}


================================================
FILE: Direct3D-Game-Demo/D3Ddemo14/DirectInputClass.h
================================================
//=============================================================================
// Name: DirectInputClass.h
//	Des: װDirectInput봦ͷļ
// 2013 203  Create by dzī 
//=============================================================================
#pragma once
#include "D3DUtil.h"
#define DIRECTINPUT_VERSION 0x0800
#include <dinput.h>

//DInputClassඨ忪ʼ
class DInputClass
{
private:
	IDirectInput8					* m_pDirectInput;   //IDirectInput8ӿڶ
	IDirectInputDevice8		* m_KeyboardDevice;  //豸ӿڶ
	char								m_keyBuffer[256];       //ڼֵ̼洢

	IDirectInputDevice8		*m_MouseDevice;      //豸ӿڶ
	DIMOUSESTATE				m_MouseState;			//ֵ洢һṹ

public:
	HRESULT		Init( HWND hWnd,HINSTANCE hInstance,DWORD keyboardCoopFlags, DWORD mouseCoopFlags ); //ʼDirectInput̼豸
	void				GetInput();   //ڻȡϢĺ
	bool				IsKeyDown(int iKey);   //жϼijǷ
	
	bool				IsMouseButtonDown(int button);  //ж갴Ƿ񱻰
	float				MouseDX();   //Xֵ
	float				MouseDY();	//Yֵ
	float				MouseDZ();	//Zֵ


public:
	DInputClass(void);		//캯
	~DInputClass(void);	//
};


================================================
FILE: Direct3D-Game-Demo/D3Ddemo15/D3DUtil.h
================================================

//*****************************************************************************************
// Desc: D3DUtil.hͷļڹĶ
// 2013 203  Create by dzī 
//*****************************************************************************************

#pragma once


#ifndef HR
#define HR(x)    { hr = x; if( FAILED(hr) ) { return hr; } }         //ԶһHRִ꣬дķ
#endif

#ifndef SAFE_DELETE					
#define SAFE_DELETE(p)       { if(p) { delete (p);     (p)=NULL; } }       //ԶһSAFE_RELEASE(),ָԴͷ
#endif    

#ifndef SAFE_RELEASE			
#define SAFE_RELEASE(p)      { if(p) { (p)->Release(); (p)=NULL; } }     //ԶһSAFE_RELEASE(),COMԴͷ
#endif

================================================
FILE: Direct3D-Game-Demo/D3Ddemo15/D3Ddemo15.cpp
================================================
//-----------------------------------˵----------------------------------------------
//  :D3Ddemo15
//	 20134 Create by dzī
//  ʵϵĹӰ : ģ弼 ʾ
//------------------------------------------------------------------------------------------------


//-----------------------------------궨岿֡--------------------------------------------
// һЩ
//------------------------------------------------------------------------------------------------
#define SCREEN_WIDTH	800						//Ϊڿȶĺ꣬Էڴ˴޸Ĵڿ
#define SCREEN_HEIGHT	600							//Ϊڸ߶ȶĺ꣬Էڴ˴޸Ĵڸ߶
#define WINDOW_TITLE	_T("ϨϷ롿 ʵϵĹӰ : ģ弼  ʾ") //Ϊڱⶨĺ


//-----------------------------------ͷļ֡---------------------------------------
//	ͷļ
//------------------------------------------------------------------------------------------------                                                                                         
#include <d3d9.h>
#include <d3dx9.h>
#include <tchar.h>
#include <time.h> 
#include "DirectInputClass.h"


//-----------------------------------ļ֡---------------------------------------
//	Ŀļ
//------------------------------------------------------------------------------------------------
#pragma comment(lib,"d3d9.lib")
#pragma comment(lib,"d3dx9.lib")
#pragma comment(lib, "dinput8.lib")     // ʹDirectInputĿļע8
#pragma comment(lib,"dxguid.lib")
#pragma comment(lib, "winmm.lib") 



//-----------------------------------ȫֱ֡-------------------------------------
//	ȫֱ
//------------------------------------------------------------------------------------------------
LPDIRECT3DDEVICE9					g_pd3dDevice = NULL; //Direct3D豸
LPD3DXFONT								g_pTextFPS				=NULL;    //COMӿ
LPD3DXFONT								g_pTextAdaperName           = NULL;  // ԿϢ2Dı
LPD3DXFONT								g_pTextHelper          = NULL;  // Ϣ2Dı
LPD3DXFONT								g_pTextInfor           = NULL;  // Ϣ2Dı
float											g_FPS								= 0.0f;       //һ͵ı֡
wchar_t										g_strFPS[50]={0};    //֡ʵַ
wchar_t										g_strAdapterName[60]={0};    //ԿƵַ
D3DXMATRIX							g_matWorld;   //
DInputClass*								g_pDInput = NULL;         //һDInputClassָ

LPD3DXMESH          g_pMesh     = NULL; // 
D3DMATERIAL9*       g_pMaterials    = NULL; // IJϢ
LPDIRECT3DTEXTURE9* g_pTextures     = NULL; // Ϣ
DWORD               g_dwNumMtrls    = 0;    // ʵĿ

LPD3DXMESH          g_pMeshWall     = NULL; // ǽ
D3DMATERIAL9        g_MaterialsWall;  // 


//-----------------------------------ȫֺ֡-------------------------------------
//	ȫֺֹδıʶϵд
//------------------------------------------------------------------------------------------------
LRESULT CALLBACK		WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam );
HRESULT						Direct3D_Init(HWND hwnd,HINSTANCE hInstance);
HRESULT						Objects_Init();
void								Direct3D_Render( HWND hwnd);
void								Direct3D_Update( HWND hwnd);
void								Direct3D_CleanUp( );
float								Get_FPS();
void								Matrix_Set();


//-----------------------------------WinMain( )--------------------------------------
//	WindowsӦóںǵij↑ʼ
//------------------------------------------------------------------------------------------------
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nShowCmd)
{

	//ʼһĴ
	WNDCLASSEX wndClass = { 0 };				//WINDCLASSEXһ࣬wndClassʵWINDCLASSEX֮󴰿ڵĸʼ    
	wndClass.cbSize = sizeof( WNDCLASSEX ) ;	//ýṹֽС
	wndClass.style = CS_HREDRAW | CS_VREDRAW;	//ôڵʽ
	wndClass.lpfnWndProc = WndProc;				//ָ򴰿ڹָ̺
	wndClass.cbClsExtra		= 0;
	wndClass.cbWndExtra		= 0;
	wndClass.hInstance = hInstance;				//ָڹ̵ijʵ
	wndClass.hIcon=(HICON)::LoadImage(NULL,_T("icon.ico"),IMAGE_ICON,0,0,LR_DEFAULTSIZE|LR_LOADFROMFILE); //ȫֵ::LoadImageӱؼԶicoͼ
	wndClass.hCursor = LoadCursor( NULL, IDC_ARROW );    //ָĹ
	wndClass.hbrBackground=(HBRUSH)GetStockObject(GRAY_BRUSH);  //ΪhbrBackgroundԱָһɫˢ
	wndClass.lpszMenuName = NULL;						//һԿַָֹ˵Դ֡
	wndClass.lpszClassName = _T("ForTheDreamOfGameDevelop");		//һԿַָֹ֡

	if( !RegisterClassEx( &wndClass ) )				//괰ںҪԴעᣬܴ͵Ĵ
		return -1;		

	HWND hwnd = CreateWindow( _T("ForTheDreamOfGameDevelop"),WINDOW_TITLE,			//ϲּĴںCreateWindow
		WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, SCREEN_WIDTH,
		SCREEN_HEIGHT, NULL, NULL, hInstance, NULL );


	//Direct3DԴijʼʧmessageboxʾ
	if (!(S_OK==Direct3D_Init (hwnd,hInstance)))
	{
		MessageBox(hwnd, _T("Direct3Dʼʧ~"), _T("dzīϢ"), 0); //ʹMessageBoxһϢ 
	}
	PlaySound(L"ɽս3.wav", NULL, SND_FILENAME | SND_ASYNC|SND_LOOP);   //ѭű

	

	MoveWindow(hwnd,200,50,SCREEN_WIDTH,SCREEN_HEIGHT,true);   //ʾʱλãϽλĻ꣨20050
	ShowWindow( hwnd, nShowCmd );    //Win32ShowWindowʾ
	UpdateWindow(hwnd);  //Դڽи£·Ҫװһ

	//DirectInputijʼ
	g_pDInput = new DInputClass();
	g_pDInput->Init(hwnd,hInstance,DISCL_FOREGROUND | DISCL_NONEXCLUSIVE,DISCL_FOREGROUND | DISCL_NONEXCLUSIVE);

	//Ϣѭ
	MSG msg = { 0 };  //ʼmsg
	while( msg.message != WM_QUIT )			//ʹwhileѭ
	{
		if( PeekMessage( &msg, 0, 0, 0, PM_REMOVE ) )   //鿴ӦóϢУϢʱеϢɷȥ
		{
			TranslateMessage( &msg );		//ϢתΪַϢ
			DispatchMessage( &msg );		//úַһϢڳ
		}
		else
		{
			Direct3D_Update(hwnd);         //øºлĸ
			Direct3D_Render(hwnd);			//ȾлȾ			
		}
	}

	UnregisterClass(_T("ForTheDreamOfGameDevelop"), wndClass.hInstance);
	return 0;  
}



//-----------------------------------WndProc( )--------------------------------------
//	ڹ̺WndProc,ԴϢд
//------------------------------------------------------------------------------------------------
LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )   //ڹ̺WndProc
{
	switch( message )				//switch俪ʼ
	{
	case WM_PAINT:					 // ͻػϢ
		Direct3D_Render(hwnd);          //Direct3D_RenderлĻ
		ValidateRect(hwnd, NULL);   // ¿ͻʾ
		break;									//switch

	case WM_KEYDOWN:                // ̰Ϣ
		if (wParam == VK_ESCAPE)    // ESC
			DestroyWindow(hwnd);    // ٴ, һWM_DESTROYϢ
		break;
	case WM_DESTROY:				//Ϣ
		Direct3D_CleanUp();     //Direct3D_CleanUpCOMӿڶ
		PostQuitMessage( 0 );		//ϵͳиֹ߳ӦWM_DESTROYϢ
		break;						//switch

	default:						//caseϣִиdefault
		return DefWindowProc( hwnd, message, wParam, lParam );		//ȱʡĴڹΪӦóûдĴϢṩȱʡĴ
	}

	return 0;					//˳
}


//-----------------------------------Direct3D_Init( )----------------------------------
//	Direct3DʼDirect3Dijʼ
//------------------------------------------------------------------------------------------------
HRESULT Direct3D_Init(HWND hwnd,HINSTANCE hInstance)
{

	//--------------------------------------------------------------------------------------
	// Direct3DʼIJ֮һӿڡDirect3Dӿڶ, ԱøDirect3D󴴽Direct3D豸
	//--------------------------------------------------------------------------------------
	LPDIRECT3D9  pD3D = NULL; //Direct3DӿڶĴ
	if( NULL == ( pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) ) //ʼDirect3Dӿڶ󣬲DirectX汾Э
 			return E_FAIL;

	//--------------------------------------------------------------------------------------
	// Direct3DʼIJ֮,ȡϢȡӲ豸Ϣ
	//--------------------------------------------------------------------------------------
	D3DCAPS9 caps; int vp = 0;
	if( FAILED( pD3D->GetDeviceCaps( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &caps ) ) )
		{
			return E_FAIL;
		}
	if( caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT )
		vp = D3DCREATE_HARDWARE_VERTEXPROCESSING;   //֧Ӳ㣬ǾͲӲ㣬׵
	else
		vp = D3DCREATE_SOFTWARE_VERTEXPROCESSING; //֧Ӳ㣬ֻò

	//--------------------------------------------------------------------------------------
	// Direct3DʼIJ֮ݡD3DPRESENT_PARAMETERSṹ
	//--------------------------------------------------------------------------------------
	D3DPRESENT_PARAMETERS d3dpp; 
	ZeroMemory(&d3dpp, sizeof(d3dpp));
	d3dpp.BackBufferWidth            = SCREEN_WIDTH;
	d3dpp.BackBufferHeight           = SCREEN_HEIGHT;
	d3dpp.BackBufferFormat           = D3DFMT_A8R8G8B8;
	d3dpp.BackBufferCount            = 2;
	d3dpp.MultiSampleType            = D3DMULTISAMPLE_NONE;
	d3dpp.MultiSampleQuality         = 0;
	d3dpp.SwapEffect                 = D3DSWAPEFFECT_DISCARD; 
	d3dpp.hDeviceWindow              = hwnd;
	d3dpp.Windowed                   = true;
	d3dpp.EnableAutoDepthStencil     = true; 
	d3dpp.AutoDepthStencilFormat     = D3DFMT_D24S8;
	d3dpp.Flags                      = 0;
	d3dpp.FullScreen_RefreshRateInHz = 0;
	d3dpp.PresentationInterval       = D3DPRESENT_INTERVAL_IMMEDIATE;

	//--------------------------------------------------------------------------------------
	// Direct3DʼIJ֮ģ豸Direct3D豸ӿ
	//--------------------------------------------------------------------------------------
	if(FAILED(pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, 
		hwnd, vp, &d3dpp, &g_pd3dDevice)))
		return E_FAIL;


	//ȡԿϢg_strAdapterNameУԿ֮ǰϡǰԿͺţַ
	 wchar_t TempName[60]=L"ǰԿͺţ";   //һʱַҷ˰"ǰԿͺţ"ַǵĿַ
	 D3DADAPTER_IDENTIFIER9 Adapter;  //һD3DADAPTER_IDENTIFIER9ṹ壬ڴ洢ԿϢ
	 pD3D->GetAdapterIdentifier(0,0,&Adapter);//GetAdapterIdentifierȡԿϢ
	 int len = MultiByteToWideChar(CP_ACP,0, Adapter.Description, -1, NULL, 0);//ԿѾAdapter.DescriptionˣΪcharͣҪתΪwchar_t
	 MultiByteToWideChar(CP_ACP, 0, Adapter.Description, -1, g_strAdapterName, len);//ⲽɺg_strAdapterNameоΪǰǵԿwchar_tַ
	 wcscat_s(TempName,g_strAdapterName);//ѵǰǵԿӵǰԿͺţַ棬TempName
	 wcscpy_s(g_strAdapterName,TempName);//TempNameеĽȫֱg_strAdapterNameУ󹦸~

	if(!(S_OK==Objects_Init())) return E_FAIL;

	SAFE_RELEASE(pD3D) //LPDIRECT3D9ӿڶʹɣǽͷŵ

	return S_OK;
}


//-----------------------------------Object_Init( )--------------------------------------
//	ȾԴʼڴ˺нҪȾԴijʼ
//--------------------------------------------------------------------------------------------------
HRESULT Objects_Init()
{
	//
	D3DXCreateFont(g_pd3dDevice, 36, 0, 0, 1000, false, DEFAULT_CHARSET, 
		OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, 0, _T("Calibri"), &g_pTextFPS);
	D3DXCreateFont(g_pd3dDevice, 20, 0, 1000, 0, false, DEFAULT_CHARSET, 
		OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, 0, L"", &g_pTextAdaperName); 
	D3DXCreateFont(g_pd3dDevice, 23, 0, 1000, 0, false, DEFAULT_CHARSET, 
		OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, 0, L"΢ź", &g_pTextHelper); 
	D3DXCreateFont(g_pd3dDevice, 26, 0, 1000, 0, false, DEFAULT_CHARSET, 
		OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, 0, L"", &g_pTextInfor); 


	// Xļм
	LPD3DXBUFFER pAdjBuffer  = NULL;
	LPD3DXBUFFER pMtrlBuffer = NULL;

	D3DXLoadMeshFromX(L"lighting.X", D3DXMESH_MANAGED, g_pd3dDevice, 
		&pAdjBuffer, &pMtrlBuffer, NULL, &g_dwNumMtrls, &g_pMesh);

	// ȡʺ
	D3DXMATERIAL *pMtrls = (D3DXMATERIAL*)pMtrlBuffer->GetBufferPointer(); //һD3DXMATERIALṹڶȡʺϢ
	g_pMaterials = new D3DMATERIAL9[g_dwNumMtrls];
	g_pTextures  = new LPDIRECT3DTEXTURE9[g_dwNumMtrls];

	for (DWORD i=0; i<g_dwNumMtrls; i++) 
	{
		//ȡʣһ»ɫֵ
		g_pMaterials[i] = pMtrls[i].MatD3D;
		g_pMaterials[i].Ambient = g_pMaterials[i].Diffuse;

		//һ
		g_pTextures[i]  = NULL;
		D3DXCreateTextureFromFileA(g_pd3dDevice, pMtrls[i].pTextureFilename, &g_pTextures[i]);
	}

	SAFE_RELEASE(pAdjBuffer)
	SAFE_RELEASE(pMtrlBuffer)


	//D3DXCreateBoxһľ
	D3DXCreateBox(g_pd3dDevice, 120.0f, 120.0f, 0.3f, &g_pMeshWall, NULL);
	g_MaterialsWall.Ambient  = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	g_MaterialsWall.Diffuse  = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	g_MaterialsWall.Specular = D3DXCOLOR(0.2f, 1.0f, 1.0f, 1.0f);


	// ù
	D3DLIGHT9 light;
	::ZeroMemory(&light, sizeof(light));
	light.Type          = D3DLIGHT_DIRECTIONAL;
	light.Ambient       = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	light.Diffuse       = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	light.Specular      = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	light.Direction     = D3DXVECTOR3(1.0f, 1.0f, 1.0f);
	g_pd3dDevice->SetLight(0, &light);
	g_pd3dDevice->LightEnable(0, true);
	g_pd3dDevice->SetRenderState(D3DRS_NORMALIZENORMALS, true);
	g_pd3dDevice->SetRenderState(D3DRS_SPECULARENABLE, true);

	return S_OK;
}


//-----------------------------------Matrix_Set( )--------------------------------------
//	װDirect3DĴ任ĺ任ȡ任ͶӰ任ӿڱ任
//--------------------------------------------------------------------------------------------------
void Matrix_Set()
{

	//--------------------------------------------------------------------------------------
	//Ĵ任֮ȡ任
	//--------------------------------------------------------------------------------------
	D3DXMATRIX matView; //һ
	D3DXVECTOR3 vEye(100.0f, 0.0f, -250.0f);  //λ
	D3DXVECTOR3 vAt(0.0f, 0.0f, 0.0f); //۲λ
	D3DXVECTOR3 vUp(0.0f, 1.0f, 0.0f);//ϵ
	D3DXMatrixLookAtLH(&matView, &vEye, &vAt, &vUp); //ȡ任
	g_pd3dDevice->SetTransform(D3DTS_VIEW, &matView); //Ӧȡ任

	//--------------------------------------------------------------------------------------
	//Ĵ任֮ͶӰ任
	//--------------------------------------------------------------------------------------
	D3DXMATRIX matProj; //һ
	D3DXMatrixPerspectiveFovLH(&matProj, D3DX_PI / 4.0f,(float)((double)SCREEN_WIDTH/SCREEN_HEIGHT),1.0f, 1000.0f); //ͶӰ任
	g_pd3dDevice->SetTransform(D3DTS_PROJECTION, &matProj);  //ͶӰ任

	//--------------------------------------------------------------------------------------
	//Ĵ任֮ġӿڱ任
	//--------------------------------------------------------------------------------------
	D3DVIEWPORT9 vp; //ʵһD3DVIEWPORT9ṹ壬ȻֵͿ
	vp.X      = 0;		//ʾӿڴڵX
	vp.Y      = 0;		//ӿԶԴڵY
	vp.Width  = SCREEN_WIDTH;	//ӿڵĿ
	vp.Height = SCREEN_HEIGHT; //ӿڵĸ߶
	vp.MinZ   = 0.0f; //ӿȻеСֵ
	vp.MaxZ   = 1.0f;	//ӿȻеֵ
	g_pd3dDevice->SetViewport(&vp); //ӿڵ

}


//-----------------------------------Direct3D_Update( )--------------------------------
//	ǼʱȾ뵫Ҫʱõģ簴ĸģ
//--------------------------------------------------------------------------------------------------
void	Direct3D_Update( HWND hwnd)
{
	//ʹDirectInputȡ
	g_pDInput->GetInput();

	// ߹رȲ
	if (g_pDInput->IsKeyDown(DIK_1))  //1Ȳ
 		g_pd3dDevice->SetRenderState(D3DRS_ZENABLE, true);
	if (g_pDInput->IsKeyDown(DIK_2))  //2رȲ
		g_pd3dDevice->SetRenderState(D3DRS_ZENABLE, false);


	// ס϶ΪƽƲ
	static FLOAT fPosX = 0.0f, fPosY = -1.5f, fPosZ = 0.0f;
	
	if (g_pDInput->IsMouseButtonDown(0)) 
	{
		fPosX += (g_pDInput->MouseDX())*  0.08f;
		fPosY += (g_pDInput->MouseDY()) * -0.08f;
	}

	//֣Ϊ۲
	fPosZ += (g_pDInput->MouseDZ())* 0.02f;

	// ƽ
	if (g_pDInput->IsKeyDown(DIK_A)) fPosX -= 0.005f;
	if (g_pDInput->IsKeyDown(DIK_D)) fPosX += 0.005f;
	if (g_pDInput->IsKeyDown(DIK_W)) fPosY += 0.005f;
	if (g_pDInput->IsKeyDown(DIK_S)) fPosY -= 0.005f;


	D3DXMatrixTranslation(&g_matWorld, fPosX, fPosY, fPosZ);


	// סҼ϶Ϊת
	static float fAngleX = 0, fAngleY =0;
	
	if (g_pDInput->IsMouseButtonDown(1)) 
	{
		fAngleX += (g_pDInput->MouseDY())* -0.01f;
		fAngleY += (g_pDInput->MouseDX()) * -0.01f;
	}
	// ת
 	if (g_pDInput->IsKeyDown(DIK_UP)) fAngleX += 0.05f;
	if (g_pDInput->IsKeyDown(DIK_DOWN)) fAngleX -= 0.05f;
 	if (g_pDInput->IsKeyDown(DIK_LEFT)) fAngleY -= 0.05f;
 	if (g_pDInput->IsKeyDown(DIK_RIGHT)) fAngleY += 0.05f;


	D3DXMATRIX Rx, Ry;
	D3DXMatrixRotationX(&Rx, fAngleX);
	D3DXMatrixRotationY(&Ry, fAngleY);

	g_matWorld = Rx * Ry * g_matWorld;

	Matrix_Set();
}



//-----------------------------------Direct3D_Render( )-------------------------------
//	ʹDirect3DȾ
//--------------------------------------------------------------------------------------------------
void Direct3D_Render(HWND hwnd)
{

	//--------------------------------------------------------------------------------------
	// Direct3DȾ岽֮һ
	//--------------------------------------------------------------------------------------
	g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER|D3DCLEAR_STENCIL, D3DCOLOR_XRGB(100, 150, 0), 1.0f, 0);

	//һΣڻȡھ
	RECT formatRect;
	GetClientRect(hwnd, &formatRect);

	//--------------------------------------------------------------------------------------
	// Direct3DȾ岽֮ʼ
	//--------------------------------------------------------------------------------------
	g_pd3dDevice->BeginScene();                     // ʼ
	
	//--------------------------------------------------------------------------------------
	// Direct3DȾ岽֮ʽ
	//--------------------------------------------------------------------------------------

	D3DXMATRIX matHero,matWorld,matRotation;   //һЩ	


	//3Dģ
	D3DXMatrixTranslation(&matHero, -20.0f, 0.0f, -25.0f);
	matHero=matHero*g_matWorld;
	g_pd3dDevice->SetTransform(D3DTS_WORLD, &matHero);//ģ͵Ϊ׼
	// һforѭģ͵ֵĻ
	for (DWORD i = 0; i < g_dwNumMtrls; i++)
	{
		g_pd3dDevice->SetMaterial(&g_pMaterials[i]);  //ô˲ֵIJ
		g_pd3dDevice->SetTexture(0, g_pTextures[i]);//ô˲ֵ
		g_pMesh->DrawSubset(i);  //ƴ˲
	}


	// Ƴ
	D3DXMatrixTranslation(&matWorld, 0.0f,0.0f,0.0f);//ǽʼ
	g_pd3dDevice->SetTransform(D3DTS_WORLD, &matWorld);//ǽ
	g_pd3dDevice->SetMaterial(&g_MaterialsWall);//ò
	g_pMeshWall->DrawSubset(0); //ǽ


	//3. ģ建棬ԼصĻ״̬á
	g_pd3dDevice->SetRenderState(D3DRS_STENCILENABLE,    true);
	g_pd3dDevice->SetRenderState(D3DRS_STENCILFUNC,      D3DCMP_ALWAYS);
	g_pd3dDevice->SetRenderState(D3DRS_STENCILREF,       0x1);
	g_pd3dDevice->SetRenderState(D3DRS_STENCILMASK,      0xffffffff);
	g_pd3dDevice->SetRenderState(D3DRS_STENCILWRITEMASK, 0xffffffff);
	g_pd3dDevice->SetRenderState(D3DRS_STENCILPASS,      D3DSTENCILOP_REPLACE);

	// 4.ںϲԼֹȻͺ̨д
	g_pd3dDevice->SetRenderState(D3DRS_ZWRITEENABLE,     false);
	g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
	g_pd3dDevice->SetRenderState(D3DRS_SRCBLEND,         D3DBLEND_ZERO);
	g_pd3dDevice->SetRenderState(D3DRS_DESTBLEND,        D3DBLEND_ONE);

	// 5.ƳΪ
	D3DXMatrixTranslation(&matWorld, 0.0f, 0.0f, 0.0f);
	g_pd3dDevice->SetTransform(D3DTS_WORLD, &matWorld);
	g_pd3dDevice->SetMaterial(&g_MaterialsWall);
	g_pMeshWall->DrawSubset(0);

	// 6.һϵȾ״̬뾵ں㣬һZ
	g_pd3dDevice->Clear(0, 0, D3DCLEAR_ZBUFFER, 0, 1.0f, 0);
	g_pd3dDevice->SetRenderState(D3DRS_ZWRITEENABLE,     true);
	g_pd3dDevice->SetRenderState(D3DRS_STENCILFUNC,      D3DCMP_EQUAL);
	g_pd3dDevice->SetRenderState(D3DRS_STENCILPASS,      D3DSTENCILOP_KEEP);
	g_pd3dDevice->SetRenderState(D3DRS_SRCBLEND,         D3DBLEND_DESTCOLOR);
	g_pd3dDevice->SetRenderState(D3DRS_DESTBLEND,        D3DBLEND_ZERO);
	g_pd3dDevice->SetRenderState(D3DRS_CULLMODE,         D3DCULL_CW);

	//7. 㾵任
	D3DXMATRIX matReflect;
	D3DXPLANE planeXY(0.0f, 0.0f, 1.0f, 0.0f); // xyƽ
	D3DXMatrixReflect(&matReflect, &planeXY);
	matWorld =  matReflect * matHero;


	//8.ƾе3Dģ
	g_pd3dDevice->SetTransform(D3DTS_WORLD, &matWorld);//ģ͵Ϊ׼
	// һforѭģ͵ֵĻ
	for (DWORD i = 0; i < g_dwNumMtrls; i++)
	{
		g_pd3dDevice->SetMaterial(&g_pMaterials[i]);  //ô˲ֵIJ
		g_pd3dDevice->SetTexture(0, g_pTextures[i]);//ô˲ֵ
		g_pMesh->DrawSubset(i);  //ƴ˲
	}


	// 9.ָȾ״̬
 	g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, false);
 	g_pd3dDevice->SetRenderState( D3DRS_STENCILENABLE,   false);
 	g_pd3dDevice->SetRenderState(D3DRS_CULLMODE,         D3DCULL_CCW);


			//ڴϽǴʾÿ֡
			formatRect.top = 5;
			int charCount = swprintf_s(g_strFPS, 20, _T("FPS:%0.3f"), Get_FPS() );
			g_pTextFPS->DrawText(NULL, g_strFPS, charCount , &formatRect, DT_TOP | DT_RIGHT, D3DCOLOR_RGBA(0,239,136,255));

			//ʾԿ
			g_pTextAdaperName->DrawText(NULL,g_strAdapterName, -1, &formatRect, 
				DT_TOP | DT_LEFT, D3DXCOLOR(1.0f, 0.5f, 0.0f, 1.0f));

			// Ϣ
			 formatRect.top = 30;
			static wchar_t strInfo[256] = {0};
			swprintf_s(strInfo,-1, L"ģ: (%.2f, %.2f, %.2f)", matHero._41, matHero._42, matHero._43);
			g_pTextHelper->DrawText(NULL, strInfo, -1, &formatRect, DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(135,239,136,255));

			// Ϣ
			formatRect.left = 0,formatRect.top = 380;
			g_pTextInfor->DrawText(NULL, L"˵:", -1, &formatRect, 
				DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(235,123,230,255));
			formatRect.top += 35;
			g_pTextHelper->DrawText(NULL, L"    ּ12߹رȲ", -1, &formatRect, 
				DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(255,200,0,255));
			formatRect.top += 25;
			g_pTextHelper->DrawText(NULL, L"    ס϶ƽģ", -1, &formatRect, 
				DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(255,200,0,255));
			formatRect.top += 25;
			g_pTextHelper->DrawText(NULL, L"    סҼ϶תģ", -1, &formatRect, 
				DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(255,200,0,255));
			formatRect.top += 25;
			g_pTextHelper->DrawText(NULL, L"    ֣ģ", -1, &formatRect, 
				DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(255,200,0,255));
			formatRect.top += 25;
			g_pTextHelper->DrawText(NULL, L"    WSADƽģ ", -1, &formatRect, 
				DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(255,200,0,255));
			formatRect.top += 25;
			g_pTextHelper->DrawText(NULL, L"    ϡ¡ҷתģ ", -1, &formatRect, 
				DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(255,200,0,255));
			formatRect.top += 25;
			g_pTextHelper->DrawText(NULL, L"    ESC : ˳", -1, &formatRect, 
				DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(255,200,0,255));


	//--------------------------------------------------------------------------------------
	// Direct3DȾ岽֮ġ
	//--------------------------------------------------------------------------------------
	g_pd3dDevice->EndScene();                       // 
	//--------------------------------------------------------------------------------------
	// Direct3DȾ岽֮塿ʾת
	//--------------------------------------------------------------------------------------
	g_pd3dDevice->Present(NULL, NULL, NULL, NULL);  // תʾ
	 
}


//-----------------------------------Get_FPS( )------------------------------------------
//	ڼÿ֡ʵһ
//--------------------------------------------------------------------------------------------------
float Get_FPS()
{

	//ĸ̬
	static float  fps = 0; //ҪFPSֵ
	static int    frameCount = 0;//֡
	static float  currentTime =0.0f;//ǰʱ
	static float  lastTime = 0.0f;//ʱ

	frameCount++;//ÿһGet_FPS()֡1
	currentTime = timeGetTime()*0.001f;//ȡϵͳʱ䣬timeGetTimeصԺΪλϵͳʱ䣬Ҫ0.001õλΪʱ

	//ǰʱȥʱ1ӣͽһFPSļͳʱĸ£ֵ֡
	if(currentTime - lastTime > 1.0f) //ʱ1
	{
		fps = (float)frameCount /(currentTime - lastTime);//1ӵFPSֵ
		lastTime = currentTime; //ǰʱcurrentTimeʱlastTimeΪһĻ׼ʱ
		frameCount    = 0;//֡frameCountֵ
	}

	return fps;
}



//-----------------------------------Direct3D_CleanUp( )--------------------------------
//	Direct3DԴͷCOMӿڶ
//---------------------------------------------------------------------------------------------------
void Direct3D_CleanUp()
{

	//ͷCOMӿڶ
	for (DWORD i = 0; i<g_dwNumMtrls; i++) 
		SAFE_RELEASE(g_pTextures[i]);

	SAFE_DELETE(g_pTextures); 
	SAFE_DELETE(g_pMaterials); 
	SAFE_DELETE(g_pDInput);
	SAFE_RELEASE(g_pMeshWall);
	SAFE_RELEASE(g_pMesh);
	SAFE_RELEASE(g_pd3dDevice);
	SAFE_RELEASE(g_pTextAdaperName)
	SAFE_RELEASE(g_pTextHelper)
	SAFE_RELEASE(g_pTextInfor)
	SAFE_RELEASE(g_pTextFPS)
	SAFE_RELEASE(g_pd3dDevice)
}

================================================
FILE: Direct3D-Game-Demo/D3Ddemo15/DirectInputClass.cpp
================================================
//=============================================================================
// Desc: DirectInput봦Դļ
// 2013 203  Create by dzī 
//=============================================================================
#include "DirectInputClass.h"


//-----------------------------------------------------------------------------
// Desc: 캯
//-----------------------------------------------------------------------------
DInputClass::DInputClass()
{
	m_pDirectInput = NULL;
	m_KeyboardDevice = NULL;
	ZeroMemory(m_keyBuffer,sizeof(char)*256);
	m_MouseDevice= NULL;
	ZeroMemory(&m_MouseState, sizeof(m_MouseState));
}


//-----------------------------------------------------------------------------
// NameDInputClass::Init(
// Desc: ʼDirectInput̼豸
//-----------------------------------------------------------------------------
HRESULT DInputClass::Init( HWND hWnd,HINSTANCE hInstance,DWORD keyboardCoopFlags, DWORD mouseCoopFlags )
{
	HRESULT hr;
	//ʼһIDirectInput8ӿڶ
	HR(DirectInput8Create( hInstance, DIRECTINPUT_VERSION, 
		IID_IDirectInput8,(void**)&m_pDirectInput,NULL ));

	//м豸ijʼ
	HR( m_pDirectInput->CreateDevice( GUID_SysKeyboard, &m_KeyboardDevice, NULL ));
	HR( m_KeyboardDevice->SetCooperativeLevel( hWnd, keyboardCoopFlags));
	HR( m_KeyboardDevice->SetDataFormat( &c_dfDIKeyboard ));
	HR( m_KeyboardDevice->Acquire( ));
	HR( m_KeyboardDevice->Poll( ));

	//豸ijʼ
	HR( m_pDirectInput->CreateDevice( GUID_SysMouse, &m_MouseDevice, NULL ));
	HR( m_MouseDevice->SetCooperativeLevel( hWnd,mouseCoopFlags));
	HR( m_MouseDevice->SetDataFormat( &c_dfDIMouse ));
	HR( m_MouseDevice->Acquire( ));
	HR( m_KeyboardDevice->Poll( ));

	return S_OK;
}


//-----------------------------------------------------------------------------
// NameDInputClass::GetInput()
// Desc: ڻȡϢĺ
//-----------------------------------------------------------------------------
void DInputClass::GetInput()
{
	HRESULT hr = m_KeyboardDevice->GetDeviceState(sizeof(m_keyBuffer), (void**)&m_keyBuffer); 
	//ȡϢ
	if(hr)
	{
		m_KeyboardDevice->Acquire();  
		m_KeyboardDevice->GetDeviceState( sizeof(m_keyBuffer),(LPVOID)m_keyBuffer );
	}

	hr = m_MouseDevice->GetDeviceState(sizeof(DIMOUSESTATE), (void**)&m_MouseState); 
	//ȡϢ
	if(hr)
	{
		m_MouseDevice->Acquire();
		m_MouseDevice->GetDeviceState( sizeof(DIMOUSESTATE), (void**)&m_MouseState);
	}
}

//-----------------------------------------------------------------------------
// NameDInputClass::IsKeyDown()
// Desc: жϼijǷ
//-----------------------------------------------------------------------------
bool DInputClass::IsKeyDown(int iKey)
{
	if(m_keyBuffer[iKey] & 0x80)
		return true;
	else
		return false;
}


//-----------------------------------------------------------------------------
// NameDInputClass::IsMouseButtonDown()
// Desc: жijǷ
//-----------------------------------------------------------------------------
bool DInputClass::IsMouseButtonDown(int button)
{
	return (m_MouseState.rgbButtons[button] & 0x80) != 0;
}

//-----------------------------------------------------------------------------
// NameDInputClass::MouseDX
// Desc: ָXֵ
//-----------------------------------------------------------------------------
float DInputClass::MouseDX()
{
	return (float)m_MouseState.lX;
}

//-----------------------------------------------------------------------------
// NameDInputClass::MouseDY
// Desc: ָYֵ
//-----------------------------------------------------------------------------
float DInputClass::MouseDY()
{
	return (float)m_MouseState.lY;
}

//-----------------------------------------------------------------------------
// NameDInputClass::MouseDZ
// Desc: ָZֵ֣
//-----------------------------------------------------------------------------
float DInputClass::MouseDZ()
{
	return (float)m_MouseState.lZ;
}




//-----------------------------------------------------------------------------
// Desc: 
//-----------------------------------------------------------------------------
DInputClass::~DInputClass(void)
{
	if(m_KeyboardDevice != NULL)
		m_KeyboardDevice->Unacquire();
	if(m_MouseDevice != NULL)
		m_MouseDevice->Unacquire();
	SAFE_RELEASE(m_KeyboardDevice);
	SAFE_RELEASE(m_MouseDevice);
	SAFE_RELEASE(m_pDirectInput);
}


================================================
FILE: Direct3D-Game-Demo/D3Ddemo15/DirectInputClass.h
================================================
//=============================================================================
// Name: DirectInputClass.h
//	Des: װDirectInput봦ͷļ
// 2013 203  Create by dzī 
//=============================================================================
#pragma once
#include "D3DUtil.h"
#define DIRECTINPUT_VERSION 0x0800
#include <dinput.h>

//DInputClassඨ忪ʼ
class DInputClass
{
private:
	IDirectInput8					* m_pDirectInput;   //IDirectInput8ӿڶ
	IDirectInputDevice8		* m_KeyboardDevice;  //豸ӿڶ
	char								m_keyBuffer[256];       //ڼֵ̼洢

	IDirectInputDevice8		*m_MouseDevice;      //豸ӿڶ
	DIMOUSESTATE				m_MouseState;			//ֵ洢һṹ

public:
	HRESULT		Init( HWND hWnd,HINSTANCE hInstance,DWORD keyboardCoopFlags, DWORD mouseCoopFlags ); //ʼDirectInput̼豸
	void				GetInput();   //ڻȡϢĺ
	bool				IsKeyDown(int iKey);   //жϼijǷ
	
	bool				IsMouseButtonDown(int button);  //ж갴Ƿ񱻰
	float				MouseDX();   //Xֵ
	float				MouseDY();	//Yֵ
	float				MouseDZ();	//Zֵ


public:
	DInputClass(void);		//캯
	~DInputClass(void);	//
};


================================================
FILE: Direct3D-Game-Demo/D3Ddemo16/CameraClass.cpp
================================================
//=============================================================================
// Name: CameraClass.cpp
//	Des: һװʵԴļ
// 2013 310  Create by dzī 
//=============================================================================
#include "CameraClass.h"

#ifndef WINDOW_WIDTH
#define WINDOW_WIDTH	800						//Ϊڿȶĺ꣬Էڴ˴޸Ĵڿ
#define WINDOW_HEIGHT	600					//Ϊڸ߶ȶĺ꣬Էڴ˴޸Ĵڸ߶
#endif

//-----------------------------------------------------------------------------
// Desc: 캯
//-----------------------------------------------------------------------------
CameraClass::CameraClass(IDirect3DDevice9 *pd3dDevice)
{
    m_pd3dDevice = pd3dDevice;
    m_vRightVector  = D3DXVECTOR3(1.0f, 0.0f, 0.0f);   // ĬXغ
    m_vUpVector     = D3DXVECTOR3(0.0f, 1.0f, 0.0f);   // ĬYغ
    m_vLookVector   = D3DXVECTOR3(0.0f, 0.0f, 1.0f);   // ĬϹ۲Zغ
    m_vCameraPosition  = D3DXVECTOR3(0.0f, 0.0f, -250.0f);   // ĬΪ(0.0f, 0.0f, -250.0f)
    m_vTargetPosition    = D3DXVECTOR3(0.0f, 0.0f, 0.0f);//ĬϹ۲ĿλΪ(0.0f, 0.0f, 0.0f);

}


//-----------------------------------------------------------------------------
// NameCameraClass::CalculateViewMatrix( )
// Desc: ݸľȡ任
//-----------------------------------------------------------------------------
VOID CameraClass::CalculateViewMatrix(D3DXMATRIX *pMatrix) 
{
	//1.Ȱ3淶ʹ໥ֱΪһ
    D3DXVec3Normalize(&m_vLookVector, &m_vLookVector);  //淶۲
    D3DXVec3Cross(&m_vUpVector, &m_vLookVector, &m_vRightVector);    // ۲ֱ
    D3DXVec3Normalize(&m_vUpVector, &m_vUpVector);                // 淶
    D3DXVec3Cross(&m_vRightVector, &m_vUpVector, &m_vLookVector);    // ֱ
    D3DXVec3Normalize(&m_vRightVector, &m_vRightVector);          // 淶


    // 2.ȡ任
	//дȡ任ĵһ
    pMatrix->_11 = m_vRightVector.x;           // Rx
    pMatrix->_12 = m_vUpVector.x;              // Ux
    pMatrix->_13 = m_vLookVector.x;            // Lx
    pMatrix->_14 = 0.0f;
	//дȡ任ĵڶ
    pMatrix->_21 = m_vRightVector.y;           // Ry
    pMatrix->_22 = m_vUpVector.y;              // Uy
    pMatrix->_23 = m_vLookVector.y;            // Ly
    pMatrix->_24 = 0.0f;
	//дȡ任ĵ
    pMatrix->_31 = m_vRightVector.z;           // Rz
    pMatrix->_32 = m_vUpVector.z;              // Uz
    pMatrix->_33 = m_vLookVector.z;            // Lz
    pMatrix->_34 = 0.0f;
	//дȡ任ĵ
    pMatrix->_41 = -D3DXVec3Dot(&m_vRightVector, &m_vCameraPosition);    // -P*R
    pMatrix->_42 = -D3DXVec3Dot(&m_vUpVector, &m_vCameraPosition);       // -P*U
    pMatrix->_43 = -D3DXVec3Dot(&m_vLookVector, &m_vCameraPosition);     // -P*L
    pMatrix->_44 = 1.0f;
}


//-----------------------------------------------------------------------------
// NameCameraClass::SetTargetPosition( )
// Desc: Ĺ۲λ
//-----------------------------------------------------------------------------
VOID CameraClass::SetTargetPosition(D3DXVECTOR3 *pLookat) 
{
	//ȿpLookatǷΪĬֵNULL
    if (pLookat != NULL)  m_vTargetPosition = (*pLookat);
    else m_vTargetPosition = D3DXVECTOR3(0.0f, 0.0f, 1.0f);

    m_vLookVector = m_vTargetPosition - m_vCameraPosition;//۲λüλãõ۲췽
    D3DXVec3Normalize(&m_vLookVector, &m_vLookVector);//淶m_vLookVector

	//淶m_vUpVectorm_vRightVector
    D3DXVec3Cross(&m_vUpVector, &m_vLookVector, &m_vRightVector);
    D3DXVec3Normalize(&m_vUpVector, &m_vUpVector);
    D3DXVec3Cross(&m_vRightVector, &m_vUpVector, &m_vLookVector);
    D3DXVec3Normalize(&m_vRightVector, &m_vRightVector);
}

//-----------------------------------------------------------------------------
// NameCameraClass::SetCameraPosition( )
// Desc: ڵλ
//-----------------------------------------------------------------------------
VOID CameraClass::SetCameraPosition(D3DXVECTOR3 *pVector) 
{
    D3DXVECTOR3 V = D3DXVECTOR3(0.0f, 0.0f, -250.0f);
    m_vCameraPosition = pVector ? (*pVector) : V;//ĿpVectorΪĻ
																		//*pVectorֵm_vCameraPosition=*pVector
																		//򷵻Vֵm_vCameraPosition=V
}

//-----------------------------------------------------------------------------
// NameCameraClass::SetViewMatrix( )
// Desc: ȡ任
//-----------------------------------------------------------------------------
VOID CameraClass::SetViewMatrix(D3DXMATRIX *pMatrix) 
{
	//pMatrixֵһж
    if (pMatrix) m_matView = *pMatrix;
    else CalculateViewMatrix(&m_matView);
    m_pd3dDevice->SetTransform(D3DTS_VIEW, &m_matView);
    //ȡ任ֱֵҷϷ͹۲
    m_vRightVector = D3DXVECTOR3(m_matView._11, m_matView._12, m_matView._13);
    m_vUpVector    = D3DXVECTOR3(m_matView._21, m_matView._22, m_matView._23);
    m_vLookVector  = D3DXVECTOR3(m_matView._31, m_matView._32, m_matView._33);
}

//-----------------------------------------------------------------------------
// NameCameraClass::SetProjMatrix( )
// Desc: ͶӰ任
//-----------------------------------------------------------------------------
VOID CameraClass::SetProjMatrix(D3DXMATRIX *pMatrix) 
{
	//жֵûУûеĻͼһ
    if (pMatrix != NULL) m_matProj = *pMatrix;
    else D3DXMatrixPerspectiveFovLH(&m_matProj, D3DX_PI / 4.0f, (float)((double)WINDOW_WIDTH/WINDOW_HEIGHT), 1.0f, 30000.0f);//ӽԶΪ30000.0fͲ¿Զ
    m_pd3dDevice->SetTransform(D3DTS_PROJECTION, &m_matProj);//ͶӰ任
}

//-----------------------------------------------------------------------------
// NameCameraClass::MoveAlongRightVec( )
// Desc: ƽfUnitsλ
//-----------------------------------------------------------------------------
VOID CameraClass::MoveAlongRightVec(FLOAT fUnits) 
{
	//ֱӳfUnitsۼӾ
    m_vCameraPosition += m_vRightVector * fUnits;
    m_vTargetPosition   += m_vRightVector * fUnits;
}

//-----------------------------------------------------------------------------
// NameCameraClass::MoveAlongUpVec( )
// Desc:  ƽfUnitsλ
//-----------------------------------------------------------------------------
VOID CameraClass::MoveAlongUpVec(FLOAT fUnits) 
{
	//ֱӳfUnitsۼӾ
    m_vCameraPosition += m_vUpVector * fUnits;
    m_vTargetPosition   += m_vUpVector * fUnits;
}

//-----------------------------------------------------------------------------
// NameCameraClass::MoveAlongLookVec( )
// Desc:  ع۲ƽfUnitsλ
//-----------------------------------------------------------------------------
VOID CameraClass::MoveAlongLookVec(FLOAT fUnits) 
{
	//ֱӳfUnitsۼӾ
    m_vCameraPosition += m_vLookVector * fUnits;
    m_vTargetPosition   += m_vLookVector * fUnits;
}

//-----------------------------------------------------------------------------
// NameCameraClass::RotationRightVec( )
// Desc:  תfAngleȵλĽǶ
//-----------------------------------------------------------------------------
VOID CameraClass::RotationRightVec(FLOAT fAngle) 
{
    D3DXMATRIX R;
    D3DXMatrixRotationAxis(&R, &m_vRightVector, fAngle);//m_vRightVectorתfAngleǶȵR
    D3DXVec3TransformCoord(&m_vUpVector, &m_vUpVector, &R);//m_vUpVectorm_vRightVectorתfAngleǶ
    D3DXVec3TransformCoord(&m_vLookVector, &m_vLookVector, &R);//m_vLookVectorm_vRightVectorתfAngleǶ

    m_vTargetPosition = m_vLookVector * D3DXVec3Length(&m_vCameraPosition);//һ¹۲λãģ=
}

//-----------------------------------------------------------------------------
// NameCameraClass::RotationUpVec( )
// Desc:  תfAngleȵλĽǶ
//-----------------------------------------------------------------------------
VOID CameraClass::RotationUpVec(FLOAT fAngle) 
{
    D3DXMATRIX R;
    D3DXMatrixRotationAxis(&R, &m_vUpVector, fAngle);//m_vUpVectorתfAngleǶȵR
    D3DXVec3TransformCoord(&m_vRightVector, &m_vRightVector, &R);//m_vRightVectorm_vUpVectorתfAngleǶ
    D3DXVec3TransformCoord(&m_vLookVector, &m_vLookVector, &R);//m_vLookVectorm_vUpVectorתfAngleǶ

    m_vTargetPosition = m_vLookVector * D3DXVec3Length(&m_vCameraPosition);//һ¹۲λãģ=
}

//-----------------------------------------------------------------------------
// NameCameraClass::RotationLookVec( )
// Desc:  ع۲תfAngleȵλĽǶ
//-----------------------------------------------------------------------------
VOID CameraClass::RotationLookVec(FLOAT fAngle) 
{
    D3DXMATRIX R;
    D3DXMatrixRotationAxis(&R, &m_vLookVector, fAngle);//m_vLookVectorתfAngleǶȵR
    D3DXVec3TransformCoord(&m_vRightVector, &m_vRightVector, &R);//m_vRightVectorm_vLookVectorתfAngleǶ
    D3DXVec3TransformCoord(&m_vUpVector, &m_vUpVector, &R);//m_vUpVectorm_vLookVectorתfAngleǶ

    m_vTargetPosition = m_vLookVector * D3DXVec3Length(&m_vCameraPosition);//һ¹۲λãģ=
}


//-----------------------------------------------------------------------------
// Desc: 
//-----------------------------------------------------------------------------
CameraClass::~CameraClass(void)
{
}


================================================
FILE: Direct3D-Game-Demo/D3Ddemo16/CameraClass.h
================================================
//=============================================================================
// Name: CameraClass.h
//	Des: һװʵͷļ
// 2013 310  Create by dzī 
//=============================================================================


#pragma once

#include <d3d9.h>
#include <d3dx9.h>

class CameraClass
{
private:
	//Ա
    D3DXVECTOR3				m_vRightVector;        // ҷ
    D3DXVECTOR3				m_vUpVector;           // Ϸ
    D3DXVECTOR3				m_vLookVector;         // ۲췽
    D3DXVECTOR3				m_vCameraPosition;        // λõ
	D3DXVECTOR3				m_vTargetPosition;        //Ŀ۲λõ
    D3DXMATRIX				m_matView;          // ȡ任
    D3DXMATRIX				m_matProj;          // ͶӰ任   
    LPDIRECT3DDEVICE9		m_pd3dDevice;  //Direct3D豸

public:
	//һȡ任ĺ
    VOID CalculateViewMatrix(D3DXMATRIX *pMatrix);    //ȡ任

	//Getϵк
    VOID GetProjMatrix(D3DXMATRIX *pMatrix)  { *pMatrix = m_matProj; }  //صǰͶӰ
    VOID GetCameraPosition(D3DXVECTOR3 *pVector)  { *pVector = m_vCameraPosition; } //صǰλþ
    VOID GetLookVector(D3DXVECTOR3 *pVector) { *pVector = m_vLookVector; }  //صǰĹ۲

	//ĸSetϵкעǶĬֵNULLģʱдҲ
    VOID SetTargetPosition(D3DXVECTOR3 *pLookat = NULL);  //Ŀ۲λ
    VOID SetCameraPosition(D3DXVECTOR3 *pVector = NULL); //ڵλ
    VOID SetViewMatrix(D3DXMATRIX *pMatrix = NULL);  //ȡ任
    VOID SetProjMatrix(D3DXMATRIX *pMatrix = NULL);  //ͶӰ任

public:
    // ظƽƵ
    VOID MoveAlongRightVec(FLOAT fUnits);   // rightƶ
    VOID MoveAlongUpVec(FLOAT fUnits);      // upƶ
    VOID MoveAlongLookVec(FLOAT fUnits);    // lookƶ

    // Ƹת
    VOID RotationRightVec(FLOAT fAngle);    // rightѡ
    VOID RotationUpVec(FLOAT fAngle);       // upת
    VOID RotationLookVec(FLOAT fAngle);     // lookת

public:
	//캯
	CameraClass(IDirect3DDevice9 *pd3dDevice);  //캯
	virtual ~CameraClass(void);  //

};


================================================
FILE: Direct3D-Game-Demo/D3Ddemo16/D3DUtil.h
================================================

//*****************************************************************************************
// Desc: D3DUtil.hͷļڹĶ
// 2013 203  Create by dzī 
//*****************************************************************************************

#pragma once


#ifndef HR
#define HR(x)    { hr = x; if( FAILED(hr) ) { return hr; } }         //ԶһHRִ꣬дķ
#endif

#ifndef SAFE_DELETE					
#define SAFE_DELETE(p)       { if(p) { delete (p);     (p)=NULL; } }       //ԶһSAFE_RELEASE(),ָԴͷ
#endif    

#ifndef SAFE_RELEASE			
#define SAFE_RELEASE(p)      { if(p) { (p)->Release(); (p)=NULL; } }     //ԶһSAFE_RELEASE(),COMԴͷ
#endif

================================================
FILE: Direct3D-Game-Demo/D3Ddemo16/D3Ddemo16.cpp
================================================
//-----------------------------------˵----------------------------------------------
//  :D3Ddemo16
//	 20134 Create by dzī
//  άռ䣺һ˳ʵ ʾ
//  ͼزij ħ3 Dota
//  زij-
//  ģزij˫6 Ԫ  ư
//------------------------------------------------------------------------------------------------


//-----------------------------------궨岿֡--------------------------------------------
// һЩ
//------------------------------------------------------------------------------------------------
#define WINDOW_WIDTH	932						//Ϊڿȶĺ꣬Էڴ˴޸Ĵڿ
#define WINDOW_HEIGHT	700							//Ϊڸ߶ȶĺ꣬Էڴ˴޸Ĵڸ߶
#define WINDOW_TITLE	_T("ϨϷ롿 άռ䣺һ˳ʵ") //Ϊڱⶨĺ


//-----------------------------------ͷļ֡---------------------------------------
//	ͷļ
//------------------------------------------------------------------------------------------------                                                                                     
#include <d3d9.h>
#include <d3dx9.h>
#include <tchar.h>
#include <time.h> 
#include "DirectInputClass.h"
#include "CameraClass.h"


//-----------------------------------ļ֡---------------------------------------
//	Ŀļ
//------------------------------------------------------------------------------------------------  
#pragma comment(lib,"d3d9.lib")
#pragma comment(lib,"d3dx9.lib")
#pragma comment(lib, "dinput8.lib")     // ʹDirectInputĿļע8
#pragma comment(lib,"dxguid.lib")
#pragma comment(lib, "winmm.lib") 


//嶥ṹ
struct CUSTOMVERTEX
{
	FLOAT _x,  _y,  _z;
	FLOAT _nx, _ny, _nz;
	FLOAT _u,  _v;
	CUSTOMVERTEX(FLOAT x, FLOAT y, FLOAT z, 
		FLOAT nx, FLOAT ny, FLOAT nz, FLOAT u, FLOAT v)
	{
		_x  = x,  _y  = y,  _z  = z;
		_nx = nx, _ny = ny, _nz = nz;
		_u  = u,  _v  = v;
	}
};
#define D3DFVF_CUSTOMVERTEX  (D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1)


//-----------------------------------ȫֱ֡-------------------------------------
//	ȫֱ
//------------------------------------------------------------------------------------------------
LPDIRECT3DDEVICE9					g_pd3dDevice = NULL; //Direct3D豸
LPD3DXFONT								g_pTextFPS				=NULL;    //COMӿ
LPD3DXFONT								g_pTextAdaperName           = NULL;  // ԿϢ2Dı
LPD3DXFONT								g_pTextHelper          = NULL;  // Ϣ2Dı
LPD3DXFONT								g_pTextInfor           = NULL;  // Ϣ2Dı
float											g_FPS								= 0.0f;       //һ͵ı֡
wchar_t										g_strFPS[50]={0};    //֡ʵַ
wchar_t										g_strAdapterName[60]={0};    //ԿƵַ
D3DXMATRIX							g_matWorld;   //
DInputClass*								g_pDInput = NULL;         //һDInputClassָ
CameraClass*							g_pCamera  = NULL;
LPD3DXMESH							g_pMesh     = NULL; // 
D3DMATERIAL9*						g_pMaterials    = NULL; // IJϢ
LPDIRECT3DTEXTURE9*				g_pTextures     = NULL; // Ϣ
DWORD									g_dwNumMtrls    = 0;    // ʵĿ
LPD3DXMESH							g_cylinder = NULL;     //
D3DMATERIAL9							g_MaterialCylinder; //
LPDIRECT3DVERTEXBUFFER9		g_pVertexBuffer           = NULL;  //ƲݵصĶ㻺
LPDIRECT3DTEXTURE9				g_pTexture             = NULL;  //Ʋݵص


//-----------------------------------ȫֺ֡-------------------------------------
//	ȫֺֹδıʶϵд
//------------------------------------------------------------------------------------------------
LRESULT CALLBACK		WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam );
HRESULT						Direct3D_Init(HWND hwnd,HINSTANCE hInstance);
HRESULT						Objects_Init();
void								Direct3D_Render( HWND hwnd);
void								Direct3D_Update( HWND hwnd);
void								Direct3D_CleanUp( );
float								Get_FPS();
void								HelpText_Render(HWND hwnd);

//-----------------------------------WinMain( )--------------------------------------
//	WindowsӦóںǵij↑ʼ
//------------------------------------------------------------------------------------------------
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nShowCmd)
{

	//ʼһĴ
	WNDCLASSEX wndClass = { 0 };				//WINDCLASSEXһ࣬wndClassʵWINDCLASSEX֮󴰿ڵĸʼ    
	wndClass.cbSize = sizeof( WNDCLASSEX ) ;	//ýṹֽС
	wndClass.style = CS_HREDRAW | CS_VREDRAW;	//ôڵʽ
	wndClass.lpfnWndProc = WndProc;				//ָ򴰿ڹָ̺
	wndClass.cbClsExtra		= 0;
	wndClass.cbWndExtra		= 0;
	wndClass.hInstance = hInstance;				//ָڹ̵ijʵ
	wndClass.hIcon=(HICON)::LoadImage(NULL,_T("icon.ico"),IMAGE_ICON,0,0,LR_DEFAULTSIZE|LR_LOADFROMFILE); //ȫֵ::LoadImageӱؼԶicoͼ
	wndClass.hCursor = LoadCursor( NULL, IDC_ARROW );    //ָĹ
	wndClass.hbrBackground=(HBRUSH)GetStockObject(GRAY_BRUSH);  //ΪhbrBackgroundԱָһɫˢ
	wndClass.lpszMenuName = NULL;						//һԿַָֹ˵Դ֡
	wndClass.lpszClassName = _T("ForTheDreamOfGameDevelop");		//һԿַָֹ֡

	if( !RegisterClassEx( &wndClass ) )				//괰ںҪԴעᣬܴ͵Ĵ
		return -1;		

	HWND hwnd = CreateWindow( _T("ForTheDreamOfGameDevelop"),WINDOW_TITLE,			//ϲּĴںCreateWindow
		WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, WINDOW_WIDTH,
		WINDOW_HEIGHT, NULL, NULL, hInstance, NULL );


	//Direct3DԴijʼʧmessageboxʾ
	if (!(S_OK==Direct3D_Init (hwnd,hInstance)))
	{
		MessageBox(hwnd, _T("Direct3Dʼʧ~"), _T("dzīϢ"), 0); //ʹMessageBoxһϢ 
	}
	PlaySound(L" - .wav", NULL, SND_FILENAME | SND_ASYNC|SND_LOOP);   //ѭű

	

	MoveWindow(hwnd,200,10,WINDOW_WIDTH,WINDOW_HEIGHT,true);   //ʾʱλãϽλĻ꣨20010
	ShowWindow( hwnd, nShowCmd );    //Win32ShowWindowʾ
	UpdateWindow(hwnd);  //Դڽи£·Ҫװһ

	//DirectInputijʼ
	g_pDInput = new DInputClass();
	g_pDInput->Init(hwnd,hInstance,DISCL_FOREGROUND | DISCL_NONEXCLUSIVE,DISCL_FOREGROUND | DISCL_NONEXCLUSIVE);

	//Ϣѭ
	MSG msg = { 0 };  //ʼmsg
	while( msg.message != WM_QUIT )			//ʹwhileѭ
	{
		if( PeekMessage( &msg, 0, 0, 0, PM_REMOVE ) )   //鿴ӦóϢУϢʱеϢɷȥ
		{
			TranslateMessage( &msg );		//ϢתΪַϢ
			DispatchMessage( &msg );		//
Download .txt
gitextract_izccgwl9/

├── .gitattributes
├── .gitignore
├── Direct3D-Game-Demo/
│   ├── D3Ddemo0/
│   │   └── D3DdemoCore.cpp
│   ├── D3Ddemo1/
│   │   └── D3Ddemo1.cpp
│   ├── D3Ddemo10/
│   │   ├── D3DUtil.h
│   │   ├── D3Ddemo10.cpp
│   │   ├── DirectInputClass.cpp
│   │   └── DirectInputClass.h
│   ├── D3Ddemo11/
│   │   ├── D3DUtil.h
│   │   ├── D3Ddemo11.cpp
│   │   ├── DirectInputClass.cpp
│   │   └── DirectInputClass.h
│   ├── D3Ddemo12/
│   │   ├── D3DUtil.h
│   │   ├── D3Ddemo12.cpp
│   │   ├── DirectInputClass.cpp
│   │   └── DirectInputClass.h
│   ├── D3Ddemo13/
│   │   ├── D3DUtil.h
│   │   ├── D3Ddemo13.cpp
│   │   ├── DirectInputClass.cpp
│   │   └── DirectInputClass.h
│   ├── D3Ddemo14/
│   │   ├── D3DUtil.h
│   │   ├── D3Ddemo14.cpp
│   │   ├── DirectInputClass.cpp
│   │   └── DirectInputClass.h
│   ├── D3Ddemo15/
│   │   ├── D3DUtil.h
│   │   ├── D3Ddemo15.cpp
│   │   ├── DirectInputClass.cpp
│   │   └── DirectInputClass.h
│   ├── D3Ddemo16/
│   │   ├── CameraClass.cpp
│   │   ├── CameraClass.h
│   │   ├── D3DUtil.h
│   │   ├── D3Ddemo16.cpp
│   │   ├── DirectInputClass.cpp
│   │   └── DirectInputClass.h
│   ├── D3Ddemo17/
│   │   ├── CameraClass.cpp
│   │   ├── CameraClass.h
│   │   ├── D3DUtil.h
│   │   ├── D3Ddemo17.cpp
│   │   ├── DirectInputClass.cpp
│   │   ├── DirectInputClass.h
│   │   ├── TerrainClass.cpp
│   │   └── TerrainClass.h
│   ├── D3Ddemo18/
│   │   ├── CameraClass.cpp
│   │   ├── CameraClass.h
│   │   ├── D3DUtil.h
│   │   ├── D3Ddemo18.cpp
│   │   ├── DirectInputClass.cpp
│   │   ├── DirectInputClass.h
│   │   ├── SkyBoxClass.cpp
│   │   ├── SkyBoxClass.h
│   │   ├── TerrainClass.cpp
│   │   └── TerrainClass.h
│   ├── D3Ddemo19/
│   │   ├── CameraClass.cpp
│   │   ├── CameraClass.h
│   │   ├── D3DUtil.h
│   │   ├── D3Ddemo19.cpp
│   │   ├── DirectInputClass.cpp
│   │   ├── DirectInputClass.h
│   │   ├── SkyBoxClass.cpp
│   │   ├── SkyBoxClass.h
│   │   ├── SnowParticleClass.cpp
│   │   ├── SnowParticleClass.h
│   │   ├── TerrainClass.cpp
│   │   └── TerrainClass.h
│   ├── D3Ddemo2/
│   │   └── D3Ddemo2.cpp
│   ├── D3Ddemo20/
│   │   ├── CameraClass.cpp
│   │   ├── CameraClass.h
│   │   ├── D3DUtil.h
│   │   ├── D3Ddemo20.cpp
│   │   ├── DirectInputClass.cpp
│   │   ├── DirectInputClass.h
│   │   ├── SkyBoxClass.cpp
│   │   ├── SkyBoxClass.h
│   │   ├── SnowParticleClass.cpp
│   │   ├── SnowParticleClass.h
│   │   ├── TerrainClass.cpp
│   │   ├── TerrainClass.h
│   │   ├── XFileModelClass.cpp
│   │   └── XFileModelClass.h
│   ├── D3Ddemo3/
│   │   └── D3Ddemo3.cpp
│   ├── D3Ddemo4/
│   │   └── D3Ddemo4.cpp
│   ├── D3Ddemo5/
│   │   └── D3Ddemo5.cpp
│   ├── D3Ddemo6/
│   │   └── D3Ddemo6.cpp
│   ├── D3Ddemo7/
│   │   └── D3Ddemo7.cpp
│   ├── D3Ddemo8/
│   │   └── D3Ddemo8.cpp
│   └── D3Ddemo9/
│       ├── D3DUtil.h
│       ├── D3Ddemo9.cpp
│       ├── DirectInputClass.cpp
│       └── DirectInputClass.h
├── GDI-Game-Demo/
│   ├── 10_GDIdemo6.cpp
│   ├── 11_GDIdemo7.cpp
│   ├── 12_GDIdemo8.cpp
│   ├── 13_GDIdemo9.cpp
│   ├── 14_GDIdemo10.cpp
│   ├── 15_GDIdemo11.cpp
│   ├── 16_GDIdemo12.cpp
│   ├── 17_GDIdemo13.cpp
│   ├── 18_GDIdemo14.cpp
│   ├── 19_GDIdemo15.cpp
│   ├── 1_HelloVisualStudio.cpp
│   ├── 20_GDIdemo16.cpp
│   ├── 21_GDIdemo17.cpp
│   ├── 2_FirstBlood!.cpp
│   ├── 3_GameCore.cpp
│   ├── 4_GDIdemoCore.cpp
│   ├── 5_GDIdemo1.cpp
│   ├── 6_GDIdemo2.cpp
│   ├── 7_GDIdemo3.cpp
│   ├── 8_GDIdemo4.cpp
│   └── 9_GDIdemo5.cpp
└── README.md
Download .txt
SYMBOL INDEX (419 symbols across 96 files)

FILE: Direct3D-Game-Demo/D3Ddemo0/D3DdemoCore.cpp
  function WinMain (line 42) | int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lp...
  function LRESULT (line 102) | LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM...
  function HRESULT (line 131) | HRESULT Direct3D_Init(HWND hwnd)
  function HRESULT (line 142) | HRESULT Objects_Init(HWND hwnd)
  function Direct3D_Render (line 151) | void Direct3D_Render(HWND hwnd)
  function Direct3D_CleanUp (line 160) | void Direct3D_CleanUp()

FILE: Direct3D-Game-Demo/D3Ddemo1/D3Ddemo1.cpp
  function WinMain (line 46) | int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lp...
  function LRESULT (line 111) | LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM...
  function HRESULT (line 140) | HRESULT Direct3D_Init(HWND hwnd)
  function HRESULT (line 201) | HRESULT Objects_Init(HWND hwnd)
  function Direct3D_Render (line 210) | void Direct3D_Render(HWND hwnd)
  function Direct3D_CleanUp (line 219) | void Direct3D_CleanUp()

FILE: Direct3D-Game-Demo/D3Ddemo10/D3Ddemo10.cpp
  type CUSTOMVERTEX (line 42) | struct CUSTOMVERTEX
    method CUSTOMVERTEX (line 46) | CUSTOMVERTEX(FLOAT x, FLOAT y, FLOAT z, FLOAT u, FLOAT v)
  function WinMain (line 84) | int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lp...
  function LRESULT (line 151) | LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM...
  function HRESULT (line 180) | HRESULT Direct3D_Init(HWND hwnd,HINSTANCE hInstance)
  function HRESULT (line 250) | HRESULT Objects_Init()
  function Matrix_Set (line 389) | void Matrix_Set()
  function Direct3D_Update (line 431) | void				Direct3D_Update( HWND hwnd)
  function Direct3D_Render (line 494) | void Direct3D_Render(HWND hwnd)
  function Get_FPS (line 582) | float Get_FPS()
  function Direct3D_CleanUp (line 610) | void Direct3D_CleanUp()

FILE: Direct3D-Game-Demo/D3Ddemo10/DirectInputClass.cpp
  function HRESULT (line 25) | HRESULT DInputClass::Init( HWND hWnd,HINSTANCE hInstance,DWORD keyboardC...

FILE: Direct3D-Game-Demo/D3Ddemo10/DirectInputClass.h
  function class (line 12) | class DInputClass

FILE: Direct3D-Game-Demo/D3Ddemo11/D3Ddemo11.cpp
  type CUSTOMVERTEX (line 42) | struct CUSTOMVERTEX
    method CUSTOMVERTEX (line 46) | CUSTOMVERTEX(FLOAT x, FLOAT y, FLOAT z, FLOAT u, FLOAT v)
  function WinMain (line 84) | int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lp...
  function LRESULT (line 152) | LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM...
  function HRESULT (line 181) | HRESULT Direct3D_Init(HWND hwnd,HINSTANCE hInstance)
  function HRESULT (line 251) | HRESULT Objects_Init()
  function Matrix_Set (line 400) | void Matrix_Set()
  function Direct3D_Update (line 442) | void				Direct3D_Update( HWND hwnd)
  function Direct3D_Render (line 525) | void Direct3D_Render(HWND hwnd)
  function Get_FPS (line 613) | float Get_FPS()
  function Direct3D_CleanUp (line 641) | void Direct3D_CleanUp()

FILE: Direct3D-Game-Demo/D3Ddemo11/DirectInputClass.cpp
  function HRESULT (line 25) | HRESULT DInputClass::Init( HWND hWnd,HINSTANCE hInstance,DWORD keyboardC...

FILE: Direct3D-Game-Demo/D3Ddemo11/DirectInputClass.h
  function class (line 12) | class DInputClass

FILE: Direct3D-Game-Demo/D3Ddemo12/D3Ddemo12.cpp
  function WinMain (line 75) | int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lp...
  function LRESULT (line 141) | LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM...
  function HRESULT (line 170) | HRESULT Direct3D_Init(HWND hwnd,HINSTANCE hInstance)
  function HRESULT (line 240) | HRESULT Objects_Init()
  function Matrix_Set (line 304) | void Matrix_Set()
  function Direct3D_Update (line 346) | void		Direct3D_Update( HWND hwnd)
  function Direct3D_Render (line 401) | void Direct3D_Render(HWND hwnd)
  function Get_FPS (line 484) | float Get_FPS()
  function Direct3D_CleanUp (line 512) | void Direct3D_CleanUp()

FILE: Direct3D-Game-Demo/D3Ddemo12/DirectInputClass.cpp
  function HRESULT (line 25) | HRESULT DInputClass::Init( HWND hWnd,HINSTANCE hInstance,DWORD keyboardC...

FILE: Direct3D-Game-Demo/D3Ddemo12/DirectInputClass.h
  function class (line 12) | class DInputClass

FILE: Direct3D-Game-Demo/D3Ddemo13/D3Ddemo13.cpp
  function WinMain (line 73) | int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lp...
  function LRESULT (line 138) | LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM...
  function HRESULT (line 167) | HRESULT Direct3D_Init(HWND hwnd,HINSTANCE hInstance)
  function HRESULT (line 237) | HRESULT Objects_Init()
  function Matrix_Set (line 313) | void Matrix_Set()
  function Direct3D_Update (line 350) | void		Direct3D_Update( HWND hwnd)
  function Direct3D_Render (line 423) | void Direct3D_Render(HWND hwnd)
  function Get_FPS (line 513) | float Get_FPS()
  function Direct3D_CleanUp (line 540) | void Direct3D_CleanUp()

FILE: Direct3D-Game-Demo/D3Ddemo13/DirectInputClass.cpp
  function HRESULT (line 25) | HRESULT DInputClass::Init( HWND hWnd,HINSTANCE hInstance,DWORD keyboardC...

FILE: Direct3D-Game-Demo/D3Ddemo13/DirectInputClass.h
  function class (line 12) | class DInputClass

FILE: Direct3D-Game-Demo/D3Ddemo14/D3Ddemo14.cpp
  function WinMain (line 77) | int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lp...
  function LRESULT (line 142) | LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM...
  function HRESULT (line 171) | HRESULT Direct3D_Init(HWND hwnd,HINSTANCE hInstance)
  function HRESULT (line 241) | HRESULT Objects_Init()
  function Matrix_Set (line 312) | void Matrix_Set()
  function Direct3D_Update (line 349) | void	Direct3D_Update( HWND hwnd)
  function Direct3D_Render (line 411) | void Direct3D_Render(HWND hwnd)
  function Get_FPS (line 508) | float Get_FPS()
  function Direct3D_CleanUp (line 535) | void Direct3D_CleanUp()

FILE: Direct3D-Game-Demo/D3Ddemo14/DirectInputClass.cpp
  function HRESULT (line 25) | HRESULT DInputClass::Init( HWND hWnd,HINSTANCE hInstance,DWORD keyboardC...

FILE: Direct3D-Game-Demo/D3Ddemo14/DirectInputClass.h
  function class (line 12) | class DInputClass

FILE: Direct3D-Game-Demo/D3Ddemo15/D3Ddemo15.cpp
  function WinMain (line 76) | int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lp...
  function LRESULT (line 143) | LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM...
  function HRESULT (line 172) | HRESULT Direct3D_Init(HWND hwnd,HINSTANCE hInstance)
  function HRESULT (line 243) | HRESULT Objects_Init()
  function Matrix_Set (line 310) | void Matrix_Set()
  function Direct3D_Update (line 348) | void	Direct3D_Update( HWND hwnd)
  function Direct3D_Render (line 411) | void Direct3D_Render(HWND hwnd)
  function Get_FPS (line 565) | float Get_FPS()
  function Direct3D_CleanUp (line 593) | void Direct3D_CleanUp()

FILE: Direct3D-Game-Demo/D3Ddemo15/DirectInputClass.cpp
  function HRESULT (line 25) | HRESULT DInputClass::Init( HWND hWnd,HINSTANCE hInstance,DWORD keyboardC...

FILE: Direct3D-Game-Demo/D3Ddemo15/DirectInputClass.h
  function class (line 12) | class DInputClass

FILE: Direct3D-Game-Demo/D3Ddemo16/CameraClass.cpp
  function VOID (line 32) | VOID CameraClass::CalculateViewMatrix(D3DXMATRIX *pMatrix)
  function VOID (line 70) | VOID CameraClass::SetTargetPosition(D3DXVECTOR3 *pLookat)
  function VOID (line 90) | VOID CameraClass::SetCameraPosition(D3DXVECTOR3 *pVector)
  function VOID (line 102) | VOID CameraClass::SetViewMatrix(D3DXMATRIX *pMatrix)
  function VOID (line 118) | VOID CameraClass::SetProjMatrix(D3DXMATRIX *pMatrix)
  function VOID (line 130) | VOID CameraClass::MoveAlongRightVec(FLOAT fUnits)
  function VOID (line 141) | VOID CameraClass::MoveAlongUpVec(FLOAT fUnits)
  function VOID (line 152) | VOID CameraClass::MoveAlongLookVec(FLOAT fUnits)
  function VOID (line 163) | VOID CameraClass::RotationRightVec(FLOAT fAngle)
  function VOID (line 177) | VOID CameraClass::RotationUpVec(FLOAT fAngle)
  function VOID (line 191) | VOID CameraClass::RotationLookVec(FLOAT fAngle)

FILE: Direct3D-Game-Demo/D3Ddemo16/CameraClass.h
  function class (line 13) | class CameraClass

FILE: Direct3D-Game-Demo/D3Ddemo16/D3Ddemo16.cpp
  type CUSTOMVERTEX (line 41) | struct CUSTOMVERTEX
    method CUSTOMVERTEX (line 46) | CUSTOMVERTEX(FLOAT x, FLOAT y, FLOAT z,
  function WinMain (line 96) | int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lp...
  function LRESULT (line 163) | LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM...
  function HRESULT (line 192) | HRESULT Direct3D_Init(HWND hwnd,HINSTANCE hInstance)
  function HRESULT (line 261) | HRESULT Objects_Init()
  function Direct3D_Update (line 353) | void	Direct3D_Update( HWND hwnd)
  function Direct3D_Render (line 419) | void Direct3D_Render(HWND hwnd)
  function HelpText_Render (line 489) | void HelpText_Render(HWND hwnd)
  function Get_FPS (line 535) | float Get_FPS()
  function Direct3D_CleanUp (line 562) | void Direct3D_CleanUp()

FILE: Direct3D-Game-Demo/D3Ddemo16/DirectInputClass.cpp
  function HRESULT (line 25) | HRESULT DInputClass::Init( HWND hWnd,HINSTANCE hInstance,DWORD keyboardC...

FILE: Direct3D-Game-Demo/D3Ddemo16/DirectInputClass.h
  function class (line 12) | class DInputClass

FILE: Direct3D-Game-Demo/D3Ddemo17/CameraClass.cpp
  function VOID (line 32) | VOID CameraClass::CalculateViewMatrix(D3DXMATRIX *pMatrix)
  function VOID (line 70) | VOID CameraClass::SetTargetPosition(D3DXVECTOR3 *pLookat)
  function VOID (line 90) | VOID CameraClass::SetCameraPosition(D3DXVECTOR3 *pVector)
  function VOID (line 102) | VOID CameraClass::SetViewMatrix(D3DXMATRIX *pMatrix)
  function VOID (line 118) | VOID CameraClass::SetProjMatrix(D3DXMATRIX *pMatrix)
  function VOID (line 130) | VOID CameraClass::MoveAlongRightVec(FLOAT fUnits)
  function VOID (line 141) | VOID CameraClass::MoveAlongUpVec(FLOAT fUnits)
  function VOID (line 152) | VOID CameraClass::MoveAlongLookVec(FLOAT fUnits)
  function VOID (line 163) | VOID CameraClass::RotationRightVec(FLOAT fAngle)
  function VOID (line 177) | VOID CameraClass::RotationUpVec(FLOAT fAngle)
  function VOID (line 191) | VOID CameraClass::RotationLookVec(FLOAT fAngle)

FILE: Direct3D-Game-Demo/D3Ddemo17/CameraClass.h
  function class (line 13) | class CameraClass

FILE: Direct3D-Game-Demo/D3Ddemo17/D3Ddemo17.cpp
  function WinMain (line 80) | int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lp...
  function LRESULT (line 145) | LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM...
  function HRESULT (line 174) | HRESULT Direct3D_Init(HWND hwnd,HINSTANCE hInstance)
  function HRESULT (line 245) | HRESULT Objects_Init()
  function Direct3D_Update (line 322) | void	Direct3D_Update( HWND hwnd)
  function Direct3D_Render (line 389) | void Direct3D_Render(HWND hwnd)
  function HelpText_Render (line 460) | void HelpText_Render(HWND hwnd)
  function Get_FPS (line 506) | float Get_FPS()
  function Direct3D_CleanUp (line 534) | void Direct3D_CleanUp()

FILE: Direct3D-Game-Demo/D3Ddemo17/DirectInputClass.cpp
  function HRESULT (line 25) | HRESULT DInputClass::Init( HWND hWnd,HINSTANCE hInstance,DWORD keyboardC...

FILE: Direct3D-Game-Demo/D3Ddemo17/DirectInputClass.h
  function class (line 12) | class DInputClass

FILE: Direct3D-Game-Demo/D3Ddemo17/TerrainClass.cpp
  function BOOL (line 35) | BOOL TerrainClass::LoadTerrainFromFile(wchar_t *pRawFileName, wchar_t *p...
  function BOOL (line 64) | BOOL TerrainClass::InitTerrain(INT nRows, INT nCols, FLOAT fSpace, FLOAT...
  function BOOL (line 147) | BOOL TerrainClass::RenderTerrain(D3DXMATRIX *pMatWorld, BOOL bRenderFrame)

FILE: Direct3D-Game-Demo/D3Ddemo17/TerrainClass.h
  function class (line 15) | class TerrainClass

FILE: Direct3D-Game-Demo/D3Ddemo18/CameraClass.cpp
  function VOID (line 32) | VOID CameraClass::CalculateViewMatrix(D3DXMATRIX *pMatrix)
  function VOID (line 70) | VOID CameraClass::SetTargetPosition(D3DXVECTOR3 *pLookat)
  function VOID (line 90) | VOID CameraClass::SetCameraPosition(D3DXVECTOR3 *pVector)
  function VOID (line 102) | VOID CameraClass::SetViewMatrix(D3DXMATRIX *pMatrix)
  function VOID (line 118) | VOID CameraClass::SetProjMatrix(D3DXMATRIX *pMatrix)
  function VOID (line 130) | VOID CameraClass::MoveAlongRightVec(FLOAT fUnits)
  function VOID (line 141) | VOID CameraClass::MoveAlongUpVec(FLOAT fUnits)
  function VOID (line 152) | VOID CameraClass::MoveAlongLookVec(FLOAT fUnits)
  function VOID (line 163) | VOID CameraClass::RotationRightVec(FLOAT fAngle)
  function VOID (line 177) | VOID CameraClass::RotationUpVec(FLOAT fAngle)
  function VOID (line 191) | VOID CameraClass::RotationLookVec(FLOAT fAngle)

FILE: Direct3D-Game-Demo/D3Ddemo18/CameraClass.h
  function class (line 13) | class CameraClass

FILE: Direct3D-Game-Demo/D3Ddemo18/D3Ddemo18.cpp
  function WinMain (line 80) | int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lp...
  function LRESULT (line 145) | LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM...
  function HRESULT (line 174) | HRESULT Direct3D_Init(HWND hwnd,HINSTANCE hInstance)
  function HRESULT (line 245) | HRESULT Objects_Init()
  function Direct3D_Update (line 326) | void	Direct3D_Update( HWND hwnd)
  function Direct3D_Render (line 393) | void Direct3D_Render(HWND hwnd)
  function HelpText_Render (line 469) | void HelpText_Render(HWND hwnd)
  function Get_FPS (line 515) | float Get_FPS()
  function Direct3D_CleanUp (line 542) | void Direct3D_CleanUp()

FILE: Direct3D-Game-Demo/D3Ddemo18/DirectInputClass.cpp
  function HRESULT (line 25) | HRESULT DInputClass::Init( HWND hWnd,HINSTANCE hInstance,DWORD keyboardC...

FILE: Direct3D-Game-Demo/D3Ddemo18/DirectInputClass.h
  function class (line 12) | class DInputClass

FILE: Direct3D-Game-Demo/D3Ddemo18/SkyBoxClass.cpp
  function BOOL (line 28) | BOOL SkyBoxClass::InitSkyBox( float Length )
  function BOOL (line 87) | BOOL SkyBoxClass::LoadSkyTextureFromFile(wchar_t *pFrontTextureFile, wch...

FILE: Direct3D-Game-Demo/D3Ddemo18/SkyBoxClass.h
  type SKYBOXVERTEX (line 10) | struct SKYBOXVERTEX
  function class (line 18) | class SkyBoxClass

FILE: Direct3D-Game-Demo/D3Ddemo18/TerrainClass.cpp
  function BOOL (line 35) | BOOL TerrainClass::LoadTerrainFromFile(wchar_t *pRawFileName, wchar_t *p...
  function BOOL (line 64) | BOOL TerrainClass::InitTerrain(INT nRows, INT nCols, FLOAT fSpace, FLOAT...
  function BOOL (line 147) | BOOL TerrainClass::RenderTerrain(D3DXMATRIX *pMatWorld, BOOL bRenderFrame)

FILE: Direct3D-Game-Demo/D3Ddemo18/TerrainClass.h
  function class (line 15) | class TerrainClass

FILE: Direct3D-Game-Demo/D3Ddemo19/CameraClass.cpp
  function VOID (line 32) | VOID CameraClass::CalculateViewMatrix(D3DXMATRIX *pMatrix)
  function VOID (line 70) | VOID CameraClass::SetTargetPosition(D3DXVECTOR3 *pLookat)
  function VOID (line 90) | VOID CameraClass::SetCameraPosition(D3DXVECTOR3 *pVector)
  function VOID (line 102) | VOID CameraClass::SetViewMatrix(D3DXMATRIX *pMatrix)
  function VOID (line 118) | VOID CameraClass::SetProjMatrix(D3DXMATRIX *pMatrix)
  function VOID (line 130) | VOID CameraClass::MoveAlongRightVec(FLOAT fUnits)
  function VOID (line 141) | VOID CameraClass::MoveAlongUpVec(FLOAT fUnits)
  function VOID (line 152) | VOID CameraClass::MoveAlongLookVec(FLOAT fUnits)
  function VOID (line 163) | VOID CameraClass::RotationRightVec(FLOAT fAngle)
  function VOID (line 177) | VOID CameraClass::RotationUpVec(FLOAT fAngle)
  function VOID (line 191) | VOID CameraClass::RotationLookVec(FLOAT fAngle)

FILE: Direct3D-Game-Demo/D3Ddemo19/CameraClass.h
  function class (line 13) | class CameraClass

FILE: Direct3D-Game-Demo/D3Ddemo19/D3Ddemo19.cpp
  function WinMain (line 88) | int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lp...
  function LRESULT (line 162) | LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM...
  function HRESULT (line 191) | HRESULT Direct3D_Init(HWND hwnd,HINSTANCE hInstance)
  function HRESULT (line 262) | HRESULT Objects_Init()
  function Direct3D_Update (line 346) | void	Direct3D_Update( HWND hwnd,FLOAT fTimeDelta)
  function Direct3D_Render (line 413) | void Direct3D_Render(HWND hwnd,FLOAT fTimeDelta)
  function HelpText_Render (line 495) | void HelpText_Render(HWND hwnd)
  function Get_FPS (line 541) | float Get_FPS()
  function Direct3D_CleanUp (line 568) | void Direct3D_CleanUp()

FILE: Direct3D-Game-Demo/D3Ddemo19/DirectInputClass.cpp
  function HRESULT (line 25) | HRESULT DInputClass::Init( HWND hWnd,HINSTANCE hInstance,DWORD keyboardC...

FILE: Direct3D-Game-Demo/D3Ddemo19/DirectInputClass.h
  function class (line 12) | class DInputClass

FILE: Direct3D-Game-Demo/D3Ddemo19/SkyBoxClass.cpp
  function BOOL (line 28) | BOOL SkyBoxClass::InitSkyBox( float Length )
  function BOOL (line 87) | BOOL SkyBoxClass::LoadSkyTextureFromFile(

FILE: Direct3D-Game-Demo/D3Ddemo19/SkyBoxClass.h
  type SKYBOXVERTEX (line 10) | struct SKYBOXVERTEX
  function class (line 18) | class SkyBoxClass

FILE: Direct3D-Game-Demo/D3Ddemo19/SnowParticleClass.cpp
  function HRESULT (line 27) | HRESULT SnowParticleClass::InitSnowParticle( )
  function HRESULT (line 80) | HRESULT SnowParticleClass::UpdateSnowParticle( float fElapsedTime)
  function HRESULT (line 104) | HRESULT SnowParticleClass::RenderSnowParticle(  )

FILE: Direct3D-Game-Demo/D3Ddemo19/SnowParticleClass.h
  type POINTVERTEX (line 18) | struct POINTVERTEX
  type SNOWPARTICLE (line 29) | struct  SNOWPARTICLE
  function class (line 42) | class SnowParticleClass

FILE: Direct3D-Game-Demo/D3Ddemo19/TerrainClass.cpp
  function BOOL (line 35) | BOOL TerrainClass::LoadTerrainFromFile(wchar_t *pRawFileName, wchar_t *p...
  function BOOL (line 64) | BOOL TerrainClass::InitTerrain(INT nRows, INT nCols, FLOAT fSpace, FLOAT...
  function BOOL (line 147) | BOOL TerrainClass::RenderTerrain(D3DXMATRIX *pMatWorld, BOOL bRenderFrame)

FILE: Direct3D-Game-Demo/D3Ddemo19/TerrainClass.h
  function class (line 15) | class TerrainClass

FILE: Direct3D-Game-Demo/D3Ddemo2/D3Ddemo2.cpp
  function WinMain (line 52) | int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lp...
  function LRESULT (line 112) | LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM...
  function HRESULT (line 141) | HRESULT Direct3D_Init(HWND hwnd)
  function HRESULT (line 201) | HRESULT Objects_Init(HWND hwnd)
  function Direct3D_Render (line 215) | void Direct3D_Render(HWND hwnd)
  function Get_FPS (line 266) | float Get_FPS()

FILE: Direct3D-Game-Demo/D3Ddemo20/CameraClass.cpp
  function VOID (line 32) | VOID CameraClass::CalculateViewMatrix(D3DXMATRIX *pMatrix)
  function VOID (line 70) | VOID CameraClass::SetTargetPosition(D3DXVECTOR3 *pLookat)
  function VOID (line 90) | VOID CameraClass::SetCameraPosition(D3DXVECTOR3 *pVector)
  function VOID (line 102) | VOID CameraClass::SetViewMatrix(D3DXMATRIX *pMatrix)
  function VOID (line 118) | VOID CameraClass::SetProjMatrix(D3DXMATRIX *pMatrix)
  function VOID (line 130) | VOID CameraClass::MoveAlongRightVec(FLOAT fUnits)
  function VOID (line 141) | VOID CameraClass::MoveAlongUpVec(FLOAT fUnits)
  function VOID (line 152) | VOID CameraClass::MoveAlongLookVec(FLOAT fUnits)
  function VOID (line 163) | VOID CameraClass::RotationRightVec(FLOAT fAngle)
  function VOID (line 177) | VOID CameraClass::RotationUpVec(FLOAT fAngle)
  function VOID (line 191) | VOID CameraClass::RotationLookVec(FLOAT fAngle)

FILE: Direct3D-Game-Demo/D3Ddemo20/CameraClass.h
  function class (line 13) | class CameraClass

FILE: Direct3D-Game-Demo/D3Ddemo20/D3Ddemo20.cpp
  function WinMain (line 83) | int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lp...
  function LRESULT (line 157) | LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM...
  function HRESULT (line 186) | HRESULT Direct3D_Init(HWND hwnd,HINSTANCE hInstance)
  function HRESULT (line 257) | HRESULT Objects_Init()
  function Direct3D_Update (line 324) | void	Direct3D_Update( HWND hwnd,FLOAT fTimeDelta)
  function Direct3D_Render (line 392) | void Direct3D_Render(HWND hwnd,FLOAT fTimeDelta)
  function HelpText_Render (line 471) | void HelpText_Render(HWND hwnd)
  function Get_FPS (line 517) | float Get_FPS()
  function Direct3D_CleanUp (line 545) | void Direct3D_CleanUp()

FILE: Direct3D-Game-Demo/D3Ddemo20/DirectInputClass.cpp
  function HRESULT (line 25) | HRESULT DInputClass::Init( HWND hWnd,HINSTANCE hInstance,DWORD keyboardC...

FILE: Direct3D-Game-Demo/D3Ddemo20/DirectInputClass.h
  function class (line 12) | class DInputClass

FILE: Direct3D-Game-Demo/D3Ddemo20/SkyBoxClass.cpp
  function BOOL (line 28) | BOOL SkyBoxClass::InitSkyBox( float Length )
  function BOOL (line 87) | BOOL SkyBoxClass::LoadSkyTextureFromFile(

FILE: Direct3D-Game-Demo/D3Ddemo20/SkyBoxClass.h
  type SKYBOXVERTEX (line 10) | struct SKYBOXVERTEX
  function class (line 18) | class SkyBoxClass

FILE: Direct3D-Game-Demo/D3Ddemo20/SnowParticleClass.cpp
  function HRESULT (line 27) | HRESULT SnowParticleClass::InitSnowParticle( )
  function HRESULT (line 80) | HRESULT SnowParticleClass::UpdateSnowParticle( float fElapsedTime)
  function HRESULT (line 104) | HRESULT SnowParticleClass::RenderSnowParticle(  )

FILE: Direct3D-Game-Demo/D3Ddemo20/SnowParticleClass.h
  type POINTVERTEX (line 18) | struct POINTVERTEX
  type SNOWPARTICLE (line 29) | struct  SNOWPARTICLE
  function class (line 42) | class SnowParticleClass

FILE: Direct3D-Game-Demo/D3Ddemo20/TerrainClass.cpp
  function BOOL (line 35) | BOOL TerrainClass::LoadTerrainFromFile(wchar_t *pRawFileName, wchar_t *p...
  function BOOL (line 64) | BOOL TerrainClass::InitTerrain(INT nRows, INT nCols, FLOAT fSpace, FLOAT...
  function BOOL (line 147) | BOOL TerrainClass::RenderTerrain(D3DXMATRIX *pMatWorld, BOOL bRenderFrame)

FILE: Direct3D-Game-Demo/D3Ddemo20/TerrainClass.h
  function class (line 15) | class TerrainClass

FILE: Direct3D-Game-Demo/D3Ddemo20/XFileModelClass.cpp
  function HRESULT (line 23) | HRESULT XFileModelClass::LoadModelFromXFile( WCHAR* strFilename )
  function HRESULT (line 68) | HRESULT XFileModelClass::RenderModel( )

FILE: Direct3D-Game-Demo/D3Ddemo20/XFileModelClass.h
  function class (line 11) | class XFileModelClass

FILE: Direct3D-Game-Demo/D3Ddemo3/D3Ddemo3.cpp
  type CUSTOMVERTEX (line 33) | struct CUSTOMVERTEX
  function WinMain (line 63) | int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lp...
  function LRESULT (line 123) | LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM...
  function HRESULT (line 152) | HRESULT Direct3D_Init(HWND hwnd)
  function HRESULT (line 212) | HRESULT Objects_Init(HWND hwnd)
  function Direct3D_Render (line 262) | void Direct3D_Render(HWND hwnd)
  function Get_FPS (line 305) | float Get_FPS()

FILE: Direct3D-Game-Demo/D3Ddemo4/D3Ddemo4.cpp
  type CUSTOMVERTEX (line 33) | struct CUSTOMVERTEX
  function WinMain (line 64) | int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lp...
  function LRESULT (line 124) | LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM...
  function HRESULT (line 153) | HRESULT Direct3D_Init(HWND hwnd)
  function HRESULT (line 214) | HRESULT Objects_Init(HWND hwnd)
  function Direct3D_Render (line 281) | void Direct3D_Render(HWND hwnd)
  function Get_FPS (line 326) | float Get_FPS()
  function Direct3D_CleanUp (line 351) | void Direct3D_CleanUp()

FILE: Direct3D-Game-Demo/D3Ddemo5/D3Ddemo5.cpp
  type CUSTOMVERTEX (line 33) | struct CUSTOMVERTEX
  function WinMain (line 65) | int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lp...
  function LRESULT (line 125) | LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM...
  function HRESULT (line 154) | HRESULT Direct3D_Init(HWND hwnd)
  function HRESULT (line 221) | HRESULT Objects_Init(HWND hwnd)
  function VOID (line 301) | VOID Matrix_Set()
  function Direct3D_Render (line 348) | void Direct3D_Render(HWND hwnd)
  function Get_FPS (line 399) | float Get_FPS()
  function Direct3D_CleanUp (line 424) | void Direct3D_CleanUp()

FILE: Direct3D-Game-Demo/D3Ddemo6/D3Ddemo6.cpp
  function WinMain (line 60) | int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lp...
  function LRESULT (line 120) | LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM...
  function HRESULT (line 149) | HRESULT Direct3D_Init(HWND hwnd)
  function HRESULT (line 210) | HRESULT Objects_Init(HWND hwnd)
  function VOID (line 240) | VOID Matrix_Set()
  function Direct3D_Render (line 281) | void Direct3D_Render(HWND hwnd)
  function Get_FPS (line 351) | float Get_FPS()
  function Direct3D_CleanUp (line 376) | void Direct3D_CleanUp()

FILE: Direct3D-Game-Demo/D3Ddemo7/D3Ddemo7.cpp
  function WinMain (line 61) | int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lp...
  function LRESULT (line 121) | LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM...
  function HRESULT (line 150) | HRESULT Direct3D_Init(HWND hwnd)
  function HRESULT (line 211) | HRESULT Objects_Init(HWND hwnd)
  function VOID (line 253) | VOID Light_Set(LPDIRECT3DDEVICE9 pd3dDevice, UINT nType)
  function VOID (line 307) | VOID Matrix_Set()
  function Direct3D_Render (line 348) | void Direct3D_Render(HWND hwnd)
  function Get_FPS (line 428) | float Get_FPS()
  function Direct3D_CleanUp (line 453) | void Direct3D_CleanUp()

FILE: Direct3D-Game-Demo/D3Ddemo8/D3Ddemo8.cpp
  function WinMain (line 81) | int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lp...
  function LRESULT (line 144) | LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM...
  function HRESULT (line 174) | HRESULT Direct3D_Init(HWND hwnd,HINSTANCE hInstance)
  function HRESULT (line 276) | HRESULT Objects_Init()
  function Matrix_Set (line 320) | void Matrix_Set()
  function Direct3D_Update (line 360) | void	Direct3D_Update( HWND hwnd)
  function Direct3D_Render (line 426) | void Direct3D_Render(HWND hwnd)
  function Get_FPS (line 509) | float Get_FPS()
  function BOOL (line 536) | BOOL Device_Read(IDirectInputDevice8 *pDIDevice, void* pBuffer, long lSize)
  function Direct3D_CleanUp (line 553) | void Direct3D_CleanUp()

FILE: Direct3D-Game-Demo/D3Ddemo9/D3Ddemo9.cpp
  function WinMain (line 72) | int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lp...
  function LRESULT (line 138) | LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM...
  function HRESULT (line 166) | HRESULT Direct3D_Init(HWND hwnd,HINSTANCE hInstance)
  function HRESULT (line 236) | HRESULT Objects_Init()
  function Matrix_Set (line 282) | void Matrix_Set()
  function Direct3D_Update (line 323) | void	Direct3D_Update( HWND hwnd)
  function Direct3D_Render (line 377) | void Direct3D_Render(HWND hwnd)
  function Get_FPS (line 454) | float Get_FPS()
  function Direct3D_CleanUp (line 482) | void Direct3D_CleanUp()

FILE: Direct3D-Game-Demo/D3Ddemo9/DirectInputClass.cpp
  function HRESULT (line 25) | HRESULT DInputClass::Init( HWND hWnd,HINSTANCE hInstance,DWORD keyboardC...

FILE: Direct3D-Game-Demo/D3Ddemo9/DirectInputClass.h
  function class (line 12) | class DInputClass

FILE: GDI-Game-Demo/10_GDIdemo6.cpp
  function WinMain (line 45) | int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lp...
  function LRESULT (line 102) | LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM...
  function BOOL (line 130) | BOOL Game_Init( HWND hwnd )
  function VOID (line 155) | VOID Game_Paint( HWND hwnd )
  function BOOL (line 172) | BOOL Game_CleanUp( HWND hwnd )

FILE: GDI-Game-Demo/11_GDIdemo7.cpp
  function WinMain (line 45) | int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lp...
  function LRESULT (line 111) | LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM...
  function BOOL (line 137) | BOOL Game_Init( HWND hwnd )
  function VOID (line 161) | VOID Game_Paint( HWND hwnd )
  function BOOL (line 177) | BOOL Game_CleanUp( HWND hwnd )

FILE: GDI-Game-Demo/12_GDIdemo8.cpp
  function WinMain (line 46) | int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lp...
  function LRESULT (line 110) | LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM...
  function BOOL (line 136) | BOOL Game_Init( HWND hwnd )
  function VOID (line 160) | VOID Game_Paint( HWND hwnd )
  function BOOL (line 190) | BOOL Game_CleanUp( HWND hwnd )

FILE: GDI-Game-Demo/13_GDIdemo9.cpp
  type Sprites (line 32) | struct Sprites        //spriteṹϵṹԱxyΪͼ꣬directionΪĿǰƶ
  function WinMain (line 58) | int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lp...
  function LRESULT (line 122) | LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM...
  function VOID (line 149) | VOID		BubSort(int n)
  function BOOL (line 178) | BOOL Game_Init( HWND hwnd )
  function VOID (line 213) | VOID Game_Paint( HWND hwnd )
  function BOOL (line 277) | BOOL Game_CleanUp( HWND hwnd )

FILE: GDI-Game-Demo/14_GDIdemo10.cpp
  function WinMain (line 47) | int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lp...
  function LRESULT (line 111) | LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM...
  function BOOL (line 168) | BOOL Game_Init( HWND hwnd )
  function VOID (line 198) | VOID Game_Paint( HWND hwnd )
  function BOOL (line 221) | BOOL Game_CleanUp( HWND hwnd )

FILE: GDI-Game-Demo/15_GDIdemo11.cpp
  type SwordBullets (line 30) | struct SwordBullets       //SwordBulletsṹӵ
  function WinMain (line 58) | int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lp...
  function LRESULT (line 122) | LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM...
  function BOOL (line 181) | BOOL Game_Init( HWND hwnd )
  function VOID (line 239) | VOID Game_Paint( HWND hwnd )
  function BOOL (line 322) | BOOL Game_CleanUp( HWND hwnd )

FILE: GDI-Game-Demo/16_GDIdemo12.cpp
  function WinMain (line 49) | int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lp...
  function LRESULT (line 113) | LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM...
  function BOOL (line 138) | BOOL Game_Init( HWND hwnd )
  function VOID (line 168) | VOID Game_Paint( HWND hwnd )
  function BOOL (line 217) | BOOL Game_CleanUp( HWND hwnd )

FILE: GDI-Game-Demo/17_GDIdemo13.cpp
  function WinMain (line 49) | int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lp...
  function LRESULT (line 113) | LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM...
  function BOOL (line 138) | BOOL Game_Init( HWND hwnd )
  function VOID (line 169) | VOID Game_Paint( HWND hwnd )
  function BOOL (line 203) | BOOL Game_CleanUp( HWND hwnd )

FILE: GDI-Game-Demo/18_GDIdemo14.cpp
  function WinMain (line 50) | int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lp...
  function LRESULT (line 114) | LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM...
  function BOOL (line 139) | BOOL Game_Init( HWND hwnd )
  function VOID (line 171) | VOID Game_Paint( HWND hwnd )
  function BOOL (line 215) | BOOL Game_CleanUp( HWND hwnd )

FILE: GDI-Game-Demo/19_GDIdemo15.cpp
  type SNOW (line 32) | struct SNOW
  function WinMain (line 61) | int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lp...
  function LRESULT (line 125) | LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM...
  function BOOL (line 150) | BOOL Game_Init( HWND hwnd )
  function VOID (line 176) | VOID Game_Paint( HWND hwnd )
  function BOOL (line 227) | BOOL Game_CleanUp( HWND hwnd )

FILE: GDI-Game-Demo/1_HelloVisualStudio.cpp
  function WinMain (line 2) | int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpC...

FILE: GDI-Game-Demo/20_GDIdemo16.cpp
  type FLYSTAR (line 34) | struct FLYSTAR
  function WinMain (line 66) | int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lp...
  function LRESULT (line 130) | LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM...
  function BOOL (line 155) | BOOL Game_Init( HWND hwnd )
  function VOID (line 181) | VOID Game_Paint( HWND hwnd )
  function BOOL (line 258) | BOOL Game_CleanUp( HWND hwnd )

FILE: GDI-Game-Demo/21_GDIdemo17.cpp
  type CHARACTER (line 34) | struct CHARACTER
  type SNOW (line 46) | struct SNOW
  type ActionTypes (line 55) | enum ActionTypes
  function WinMain (line 102) | int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lp...
  function LRESULT (line 166) | LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM...
  function BOOL (line 215) | BOOL Game_Init( HWND hwnd )
  function VOID (line 280) | VOID Game_Main( HWND hwnd )
  function Message_Insert (line 416) | void Message_Insert(wchar_t* str)
  function Die_Check (line 437) | void Die_Check(int NowHp,bool isHero)
  function VOID (line 462) | VOID		HeroAction_Logic( )
  function VOID (line 534) | VOID HeroAction_Paint()
  function VOID (line 563) | VOID BossAction_Logic()
  function VOID (line 601) | VOID		BossAction_Paint()
  function VOID (line 675) | VOID Snow_Paint()
  function BOOL (line 716) | BOOL Game_ShutDown( HWND hwnd )

FILE: GDI-Game-Demo/2_FirstBlood!.cpp
  function WinMain (line 3) | int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpC...

FILE: GDI-Game-Demo/3_GameCore.cpp
  function WinMain (line 31) | int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lp...
  function LRESULT (line 81) | LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM...

FILE: GDI-Game-Demo/4_GDIdemoCore.cpp
  function WinMain (line 36) | int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lp...
  function LRESULT (line 92) | LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM...
  function BOOL (line 125) | BOOL Game_Init( HWND hwnd )
  function VOID (line 135) | VOID Game_Paint( HWND hwnd )
  function BOOL (line 143) | BOOL Game_CleanUp( HWND hwnd )

FILE: GDI-Game-Demo/5_GDIdemo1.cpp
  function WinMain (line 47) | int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lp...
  function LRESULT (line 104) | LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM...
  function BOOL (line 137) | BOOL Game_Init( HWND hwnd )
  function VOID (line 160) | VOID Game_Paint( HWND hwnd )
  function BOOL (line 193) | BOOL Game_CleanUp( HWND hwnd )

FILE: GDI-Game-Demo/6_GDIdemo2.cpp
  function WinMain (line 42) | int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lp...
  function LRESULT (line 99) | LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM...
  function BOOL (line 132) | BOOL Game_Init( HWND hwnd )
  function VOID (line 143) | VOID Game_Paint( HWND hwnd )
  function BOOL (line 170) | BOOL Game_CleanUp( HWND hwnd )

FILE: GDI-Game-Demo/7_GDIdemo3.cpp
  function WinMain (line 42) | int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lp...
  function LRESULT (line 99) | LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM...
  function BOOL (line 132) | BOOL Game_Init( HWND hwnd )
  function VOID (line 150) | VOID Game_Paint( HWND hwnd )
  function BOOL (line 161) | BOOL Game_CleanUp( HWND hwnd )

FILE: GDI-Game-Demo/8_GDIdemo4.cpp
  function WinMain (line 42) | int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lp...
  function LRESULT (line 99) | LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM...
  function BOOL (line 132) | BOOL Game_Init( HWND hwnd )
  function VOID (line 153) | VOID Game_Paint( HWND hwnd )
  function BOOL (line 173) | BOOL Game_CleanUp( HWND hwnd )

FILE: GDI-Game-Demo/9_GDIdemo5.cpp
  function WinMain (line 43) | int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lp...
  function LRESULT (line 100) | LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM...
  function BOOL (line 133) | BOOL Game_Init( HWND hwnd )
  function VOID (line 153) | VOID Game_Paint( HWND hwnd )
  function BOOL (line 171) | BOOL Game_CleanUp( HWND hwnd )
Condensed preview — 111 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (803K chars).
[
  {
    "path": ".gitattributes",
    "chars": 378,
    "preview": "# Auto detect text files and perform LF normalization\n* text=auto\n\n# Custom for Visual Studio\n*.cs     diff=csharp\n\n# St"
  },
  {
    "path": ".gitignore",
    "chars": 574,
    "preview": "# Windows image file caches\nThumbs.db\nehthumbs.db\n\n# Folder config file\nDesktop.ini\n\n# Recycle Bin used on file shares\n$"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo0/D3DdemoCore.cpp",
    "chars": 5771,
    "preview": "\n//-----------------------------------˵----------------------------------------------\n//  :D3DdemoCore\n//\t 20134 Create "
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo1/D3Ddemo1.cpp",
    "chars": 8202,
    "preview": "\n//-----------------------------------˵----------------------------------------------\n//  :D3Ddemo1\n//\t 20134 Create by "
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo10/D3DUtil.h",
    "chars": 589,
    "preview": "\n//=============================================================================\n// Desc: D3DUtil.hͷļڹĶ\n// 2013 203  Cre"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo10/D3Ddemo10.cpp",
    "chars": 23375,
    "preview": "//-----------------------------------˵----------------------------------------------\n//  :D3Ddemo10\n//\t 20134 Create by "
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo10/DirectInputClass.cpp",
    "chars": 4182,
    "preview": "//=============================================================================\n// Desc: DirectInput봦Դļ\n// 2013 203  Cre"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo10/DirectInputClass.h",
    "chars": 997,
    "preview": "//=============================================================================\n// Name: DirectInputClass.h\n//\tDes: װDir"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo11/D3DUtil.h",
    "chars": 589,
    "preview": "\n//=============================================================================\n// Desc: D3DUtil.hͷļڹĶ\n// 2013 203  Cre"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo11/D3Ddemo11.cpp",
    "chars": 24459,
    "preview": "//-----------------------------------˵----------------------------------------------\n//  :D3Ddemo10\n//\t 20134 Create by "
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo11/DirectInputClass.cpp",
    "chars": 4182,
    "preview": "//=============================================================================\n// Desc: DirectInput봦Դļ\n// 2013 203  Cre"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo11/DirectInputClass.h",
    "chars": 997,
    "preview": "//=============================================================================\n// Name: DirectInputClass.h\n//\tDes: װDir"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo12/D3DUtil.h",
    "chars": 613,
    "preview": "\n//*****************************************************************************************\n// Desc: D3DUtil.hͷļڹĶ\n// 2"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo12/D3Ddemo12.cpp",
    "chars": 19225,
    "preview": "//-----------------------------------˵----------------------------------------------\n//  :D3Ddemo12\n//\t 20134 Create by "
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo12/DirectInputClass.cpp",
    "chars": 4182,
    "preview": "//=============================================================================\n// Desc: DirectInput봦Դļ\n// 2013 203  Cre"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo12/DirectInputClass.h",
    "chars": 997,
    "preview": "//=============================================================================\n// Name: DirectInputClass.h\n//\tDes: װDir"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo13/D3DUtil.h",
    "chars": 613,
    "preview": "\n//*****************************************************************************************\n// Desc: D3DUtil.hͷļڹĶ\n// 2"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo13/D3Ddemo13.cpp",
    "chars": 20021,
    "preview": "//-----------------------------------˵----------------------------------------------\n//  :D3Ddemo13\n//\t 20134 Create by "
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo13/DirectInputClass.cpp",
    "chars": 4182,
    "preview": "//=============================================================================\n// Desc: DirectInput봦Դļ\n// 2013 203  Cre"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo13/DirectInputClass.h",
    "chars": 997,
    "preview": "//=============================================================================\n// Name: DirectInputClass.h\n//\tDes: װDir"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo14/D3DUtil.h",
    "chars": 613,
    "preview": "\n//*****************************************************************************************\n// Desc: D3DUtil.hͷļڹĶ\n// 2"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo14/D3Ddemo14.cpp",
    "chars": 20205,
    "preview": "//-----------------------------------˵----------------------------------------------\n//  :D3Ddemo13\n//\t 20134 Create by "
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo14/DirectInputClass.cpp",
    "chars": 4182,
    "preview": "//=============================================================================\n// Desc: DirectInput봦Դļ\n// 2013 203  Cre"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo14/DirectInputClass.h",
    "chars": 997,
    "preview": "//=============================================================================\n// Name: DirectInputClass.h\n//\tDes: װDir"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo15/D3DUtil.h",
    "chars": 613,
    "preview": "\n//*****************************************************************************************\n// Desc: D3DUtil.hͷļڹĶ\n// 2"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo15/D3Ddemo15.cpp",
    "chars": 22118,
    "preview": "//-----------------------------------˵----------------------------------------------\n//  :D3Ddemo15\n//\t 20134 Create by "
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo15/DirectInputClass.cpp",
    "chars": 4182,
    "preview": "//=============================================================================\n// Desc: DirectInput봦Դļ\n// 2013 203  Cre"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo15/DirectInputClass.h",
    "chars": 997,
    "preview": "//=============================================================================\n// Name: DirectInputClass.h\n//\tDes: װDir"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo16/CameraClass.cpp",
    "chars": 8380,
    "preview": "//=============================================================================\n// Name: CameraClass.cpp\n//\tDes: һװʵԴļ\n/"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo16/CameraClass.h",
    "chars": 1748,
    "preview": "//=============================================================================\n// Name: CameraClass.h\n//\tDes: һװʵͷļ\n// "
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo16/D3DUtil.h",
    "chars": 613,
    "preview": "\n//*****************************************************************************************\n// Desc: D3DUtil.hͷļڹĶ\n// 2"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo16/D3Ddemo16.cpp",
    "chars": 21253,
    "preview": "//-----------------------------------˵----------------------------------------------\n//  :D3Ddemo16\n//\t 20134 Create by "
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo16/DirectInputClass.cpp",
    "chars": 4182,
    "preview": "//=============================================================================\n// Desc: DirectInput봦Դļ\n// 2013 203  Cre"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo16/DirectInputClass.h",
    "chars": 997,
    "preview": "//=============================================================================\n// Name: DirectInputClass.h\n//\tDes: װDir"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo17/CameraClass.cpp",
    "chars": 8382,
    "preview": "//=============================================================================\n// Name: CameraClass.cpp\n//\tDes: һװʵԴļ\n/"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo17/CameraClass.h",
    "chars": 1748,
    "preview": "//=============================================================================\n// Name: CameraClass.h\n//\tDes: һװʵͷļ\n// "
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo17/D3DUtil.h",
    "chars": 613,
    "preview": "\n//*****************************************************************************************\n// Desc: D3DUtil.hͷļڹĶ\n// 2"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo17/D3Ddemo17.cpp",
    "chars": 20132,
    "preview": "//-----------------------------------˵----------------------------------------------\n//  :D3Ddemo17\n//\t 20134 Create by "
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo17/DirectInputClass.cpp",
    "chars": 4185,
    "preview": "//=============================================================================\n// Desc: DirectInput봦Դļ\n// 2013 203  Cre"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo17/DirectInputClass.h",
    "chars": 997,
    "preview": "//=============================================================================\n// Name: DirectInputClass.h\n//\tDes: װDir"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo17/TerrainClass.cpp",
    "chars": 6595,
    "preview": "//=============================================================================\n// Name: TerrainClass.cpp\n//\tDes: һװάϵͳԴ"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo17/TerrainClass.h",
    "chars": 1582,
    "preview": "//=============================================================================\n// Name: TerrainClass.h\n//\tDes: һװάϵͳͷļ\n"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo18/CameraClass.cpp",
    "chars": 8375,
    "preview": "//=============================================================================\n// Name: CameraClass.cpp\n//\tDes: һװʵԴļ\n/"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo18/CameraClass.h",
    "chars": 1748,
    "preview": "//=============================================================================\n// Name: CameraClass.h\n//\tDes: һװʵͷļ\n// "
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo18/D3DUtil.h",
    "chars": 613,
    "preview": "\n//*****************************************************************************************\n// Desc: D3DUtil.hͷļڹĶ\n// 2"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo18/D3Ddemo18.cpp",
    "chars": 20641,
    "preview": "//-----------------------------------˵----------------------------------------------\n//  :D3Ddemo18\n//\t 20134 Create by "
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo18/DirectInputClass.cpp",
    "chars": 4182,
    "preview": "//=============================================================================\n// Desc: DirectInput봦Դļ\n// 2013 203  Cre"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo18/DirectInputClass.h",
    "chars": 997,
    "preview": "//=============================================================================\n// Name: DirectInputClass.h\n//\tDes: װDir"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo18/SkyBoxClass.cpp",
    "chars": 4901,
    "preview": "//=============================================================================\n// Name: SkyBoxClass.cpp\n//\tDes: һװάպϵͳԴ"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo18/SkyBoxClass.h",
    "chars": 979,
    "preview": "//=============================================================================\n// Name: SkyBoxClass.h\n//\tDes: һװάպϵͳͷļ\n"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo18/TerrainClass.cpp",
    "chars": 6592,
    "preview": "//=============================================================================\n// Name: TerrainClass.cpp\n//\tDes: һװάϵͳԴ"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo18/TerrainClass.h",
    "chars": 1582,
    "preview": "//=============================================================================\n// Name: TerrainClass.h\n//\tDes: һװάϵͳͷļ\n"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo19/CameraClass.cpp",
    "chars": 8375,
    "preview": "//=============================================================================\n// Name: CameraClass.cpp\n//\tDes: һװʵԴļ\n/"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo19/CameraClass.h",
    "chars": 1748,
    "preview": "//=============================================================================\n// Name: CameraClass.h\n//\tDes: һװʵͷļ\n// "
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo19/D3DUtil.h",
    "chars": 613,
    "preview": "\n//*****************************************************************************************\n// Desc: D3DUtil.hͷļڹĶ\n// 2"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo19/D3Ddemo19.cpp",
    "chars": 21498,
    "preview": "\n//-----------------------------------˵----------------------------------------------\n//  :D3Ddemo19\n//\t 20134 Create by"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo19/DirectInputClass.cpp",
    "chars": 4182,
    "preview": "//=============================================================================\n// Desc: DirectInput봦Դļ\n// 2013 203  Cre"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo19/DirectInputClass.h",
    "chars": 997,
    "preview": "//=============================================================================\n// Name: DirectInputClass.h\n//\tDes: װDir"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo19/SkyBoxClass.cpp",
    "chars": 4961,
    "preview": "//=============================================================================\n// Name: SkyBoxClass.cpp\n//\tDes: һװάպϵͳԴ"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo19/SkyBoxClass.h",
    "chars": 979,
    "preview": "//=============================================================================\n// Name: SkyBoxClass.h\n//\tDes: һװάպϵͳͷļ\n"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo19/SnowParticleClass.cpp",
    "chars": 5559,
    "preview": "//=============================================================================\n// Name: SnowParticleClass.cpp\n//\tDes: һ"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo19/SnowParticleClass.h",
    "chars": 1885,
    "preview": "//=============================================================================\n// Name: SnowParticleClass.h\n//\tDes: һװѩ"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo19/TerrainClass.cpp",
    "chars": 6592,
    "preview": "//=============================================================================\n// Name: TerrainClass.cpp\n//\tDes: һװάϵͳԴ"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo19/TerrainClass.h",
    "chars": 1582,
    "preview": "//=============================================================================\n// Name: TerrainClass.h\n//\tDes: һװάϵͳͷļ\n"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo2/D3Ddemo2.cpp",
    "chars": 11163,
    "preview": "\n//-----------------------------------˵----------------------------------------------\n//  :D3Ddemo2\n//\t 20134 Create by "
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo20/CameraClass.cpp",
    "chars": 8374,
    "preview": "//=============================================================================\n// Name: CameraClass.cpp\n//\tDes: һװʵԴļ\n/"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo20/CameraClass.h",
    "chars": 1748,
    "preview": "//=============================================================================\n// Name: CameraClass.h\n//\tDes: һװʵͷļ\n// "
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo20/D3DUtil.h",
    "chars": 720,
    "preview": "\n//*****************************************************************************************\n// Desc: D3DUtil.hͷļڹĶ\n// 2"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo20/D3Ddemo20.cpp",
    "chars": 20795,
    "preview": "\n//-----------------------------------˵----------------------------------------------\n//  :D3Ddemo20\n//\t 20134 Create by"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo20/DirectInputClass.cpp",
    "chars": 4182,
    "preview": "//=============================================================================\n// Desc: DirectInput봦Դļ\n// 2013 203  Cre"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo20/DirectInputClass.h",
    "chars": 997,
    "preview": "//=============================================================================\n// Name: DirectInputClass.h\n//\tDes: װDir"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo20/SkyBoxClass.cpp",
    "chars": 5108,
    "preview": "//=============================================================================\n// Name: SkyBoxClass.cpp\n//\tDes: һװάպϵͳԴ"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo20/SkyBoxClass.h",
    "chars": 979,
    "preview": "//=============================================================================\n// Name: SkyBoxClass.h\n//\tDes: һװάպϵͳͷļ\n"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo20/SnowParticleClass.cpp",
    "chars": 5559,
    "preview": "//=============================================================================\n// Name: SnowParticleClass.cpp\n//\tDes: һ"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo20/SnowParticleClass.h",
    "chars": 1884,
    "preview": "//=============================================================================\n// Name: SnowParticleClass.h\n//\tDes: һװѩ"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo20/TerrainClass.cpp",
    "chars": 6592,
    "preview": "//=============================================================================\n// Name: TerrainClass.cpp\n//\tDes: һװάϵͳԴ"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo20/TerrainClass.h",
    "chars": 1582,
    "preview": "//=============================================================================\n// Name: TerrainClass.h\n//\tDes: һװάϵͳͷļ\n"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo20/XFileModelClass.cpp",
    "chars": 2935,
    "preview": "//=============================================================================\n// Name: XFileModelClass.h\n//\tDes: һװXļȾ"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo20/XFileModelClass.h",
    "chars": 716,
    "preview": "//=============================================================================\n// Name: XFileModelClass.h\n//\tDes: һװXļȾ"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo3/D3Ddemo3.cpp",
    "chars": 13112,
    "preview": "//-----------------------------------˵----------------------------------------------\n//  :D3Ddemo3\n//\t 20134 Create by dz"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo4/D3Ddemo4.cpp",
    "chars": 13491,
    "preview": "//-----------------------------------˵----------------------------------------------\n//  :D3Ddemo4\n//\t 20134 Create by dz"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo5/D3Ddemo5.cpp",
    "chars": 16746,
    "preview": "//-----------------------------------˵----------------------------------------------\n//  :D3Ddemo5\n//\t 20134 Create by dz"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo6/D3Ddemo6.cpp",
    "chars": 14583,
    "preview": "//-----------------------------------˵----------------------------------------------\n//  :D3Ddemo6\n//\t 20134 Create by dz"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo7/D3Ddemo7.cpp",
    "chars": 17129,
    "preview": "//-----------------------------------˵----------------------------------------------\n//  :D3Ddemo7\n//\t 20134 Create by dz"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo8/D3Ddemo8.cpp",
    "chars": 21422,
    "preview": "//-----------------------------------˵----------------------------------------------\n//  :D3Ddemo8\n//\t 20134 Create by dz"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo9/D3DUtil.h",
    "chars": 589,
    "preview": "\n//=============================================================================\n// Desc: D3DUtil.hͷļڹĶ\n// 2013 203  Cre"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo9/D3Ddemo9.cpp",
    "chars": 18335,
    "preview": "//-----------------------------------˵----------------------------------------------\n//  :D3Ddemo9\n//\t 20134 Create by dz"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo9/DirectInputClass.cpp",
    "chars": 4182,
    "preview": "//=============================================================================\n// Desc: DirectInput봦Դļ\n// 2013 203  Cre"
  },
  {
    "path": "Direct3D-Game-Demo/D3Ddemo9/DirectInputClass.h",
    "chars": 997,
    "preview": "//=============================================================================\n// Name: DirectInputClass.h\n//\tDes: װDir"
  },
  {
    "path": "GDI-Game-Demo/10_GDIdemo6.cpp",
    "chars": 6290,
    "preview": "\n//-----------------------------------˵----------------------------------------------\n//  :GDIdemo6\n//\t 20133 Create by "
  },
  {
    "path": "GDI-Game-Demo/11_GDIdemo7.cpp",
    "chars": 6169,
    "preview": "\n//-----------------------------------˵----------------------------------------------\n//  :GDIdemo7\n//\t 20133 Create by "
  },
  {
    "path": "GDI-Game-Demo/12_GDIdemo8.cpp",
    "chars": 6766,
    "preview": "\n//-----------------------------------˵----------------------------------------------\n//  :GDIdemo8\n//\t 20133 Create by "
  },
  {
    "path": "GDI-Game-Demo/13_GDIdemo9.cpp",
    "chars": 8832,
    "preview": "\n//-----------------------------------˵----------------------------------------------\n//  :GDIdemo10\n//\t 20133 Create by"
  },
  {
    "path": "GDI-Game-Demo/14_GDIdemo10.cpp",
    "chars": 7584,
    "preview": "\n//-----------------------------------˵----------------------------------------------\n//  :GDIdemo10\n//\t 20133 Create by"
  },
  {
    "path": "GDI-Game-Demo/15_GDIdemo11.cpp",
    "chars": 9533,
    "preview": "\n//-----------------------------------˵----------------------------------------------\n//  :GDIdemo11\n//\t 20133 Create by"
  },
  {
    "path": "GDI-Game-Demo/16_GDIdemo12.cpp",
    "chars": 7003,
    "preview": "\n//-----------------------------------˵----------------------------------------------\n//  :GDIdemo12\n//\t 20133 Create by"
  },
  {
    "path": "GDI-Game-Demo/17_GDIdemo13.cpp",
    "chars": 7045,
    "preview": "\n//-----------------------------------˵----------------------------------------------\n//  :GDIdemo13\n//\t 20133 Create by"
  },
  {
    "path": "GDI-Game-Demo/18_GDIdemo14.cpp",
    "chars": 7491,
    "preview": "\n//-----------------------------------˵----------------------------------------------\n//  :GDIdemo14\n//\t 20133 Create by"
  },
  {
    "path": "GDI-Game-Demo/19_GDIdemo15.cpp",
    "chars": 7521,
    "preview": "\n//-----------------------------------˵----------------------------------------------\n//  :GDIdemo4\n//\t 20133 Create by "
  },
  {
    "path": "GDI-Game-Demo/1_HelloVisualStudio.cpp",
    "chars": 201,
    "preview": "#include <Windows.h>\nint WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)\n{ \n\tMe"
  },
  {
    "path": "GDI-Game-Demo/20_GDIdemo16.cpp",
    "chars": 8315,
    "preview": "\n//-----------------------------------˵----------------------------------------------\n//  :GDIdemo16\n//\t 20133 Create by"
  },
  {
    "path": "GDI-Game-Demo/21_GDIdemo17.cpp",
    "chars": 21471,
    "preview": "\n//-----------------------------------˵----------------------------------------------\n//  :GDIdemo17\n//\t 20133 Create by"
  },
  {
    "path": "GDI-Game-Demo/2_FirstBlood!.cpp",
    "chars": 305,
    "preview": "#include <Windows.h>\n#pragma comment(lib,\"winmm.lib\")\nint WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPS"
  },
  {
    "path": "GDI-Game-Demo/3_GameCore.cpp",
    "chars": 3648,
    "preview": "\n//-----------------------------------˵----------------------------------------------\n//  :GameCore\n//\t 20133 Create by "
  },
  {
    "path": "GDI-Game-Demo/4_GDIdemoCore.cpp",
    "chars": 5145,
    "preview": "\n//-----------------------------------˵----------------------------------------------\n//  :GDIdemoCore\n//\t 20133 Create "
  },
  {
    "path": "GDI-Game-Demo/5_GDIdemo1.cpp",
    "chars": 6626,
    "preview": "\n//-----------------------------------˵----------------------------------------------\n//  :GDIdemoCore\n//\t 20133 Create "
  },
  {
    "path": "GDI-Game-Demo/6_GDIdemo2.cpp",
    "chars": 6059,
    "preview": "\n//-----------------------------------˵----------------------------------------------\n//  :GDIdemoCore\n//\t 20133 Create "
  },
  {
    "path": "GDI-Game-Demo/7_GDIdemo3.cpp",
    "chars": 5934,
    "preview": "\n//-----------------------------------˵----------------------------------------------\n//  :GDIdemoCore\n//\t 20133 Create "
  },
  {
    "path": "GDI-Game-Demo/8_GDIdemo4.cpp",
    "chars": 6590,
    "preview": "\n//-----------------------------------˵----------------------------------------------\n//  :GDIdemo4\n//\t 20133 Create by "
  },
  {
    "path": "GDI-Game-Demo/9_GDIdemo5.cpp",
    "chars": 6527,
    "preview": "\n//-----------------------------------˵----------------------------------------------\n//  :GDIdemo5\n//\t 20133 Create by "
  },
  {
    "path": "README.md",
    "chars": 3908,
    "preview": "《逐梦旅程:Windows游戏编程之从零开始》源代码\n===============================\n<BR>\n\n# 简介\n这是我在23岁出国留学期间,花费一年时间所著的一本关于如何利用Win32和Direct3D、C++开"
  }
]

About this extraction

This page contains the full source code of the QianMo/Direct3D-Win32-Book-Src-Code GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 111 files (696.2 KB), approximately 240.7k tokens, and a symbol index with 419 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!