最简单的d3d

#include "3D_Draw.h"

/************************************************************************/
/* initializing Direct3D steps       
1. fill IDirect3D9 and IDirect3DDevice9
2. D3DCAPS9, check the display adapter supports hardware vetex processing or not
3. D3DPRESENT_PARAMETERS, it will specify the characteristics of the IDirect3DDevice9
4. Create the IDirect3DDevice9, it will represents the physical hardware device
*/
/************************************************************************/

IDirect3D9* _d3d9 = NULL;
IDirect3DDevice9* g_pd3dDevice = NULL;
D3DDEVTYPE deviceType = D3DDEVTYPE_HAL;
HRESULT InitD3D( HWND hWnd)
{
//1.Create IDirect3D9, 这个对象有两个用途,一个是设备枚举,另一个就是创建IDirect3DDevice9
	//设备枚举:device enumeration 获取显卡的性能,显示模式,格式及其他信息
	_d3d9 = Direct3DCreate9(D3D_SDK_VERSION); //D3D_SDK_VERSION 保证使用正确的头文件

	if (NULL == _d3d9)
	{
	::MessageBox(NULL,"create Direct3D failed",NULL,0);
	return 0;
	}

//2. Check for hardware vp.检查定点运算类型
	//not all cards support hardware vertex processing, we must check it
	//建议在使用之前总是检查一下设备性能性能,看设备是否支持该特性

	//Fill the D3DCAPS9 structure with the apabilities of the primary display adapter
	D3DCAPS9 caps;
	_d3d9->GetDeviceCaps(D3DADAPTER_DEFAULT,    //Specifies the physical display adapter
		deviceType,                             //Specifies the device type to use or software device
		&caps);                                 //return the initialized capabilities structure
	// Can we use hardware vertex processing?
	int vp = 0; //注意,这个地方用vp保存了定点运算类型
	if( caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT )
	{
		// yes, save in 'vp' the fact that hardware vertex
		// processing is supported.
		vp = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
	}
	else
	{
		// no, save in 'vp' the fact that we must use software
		// vertex processing.
		vp = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
	}

//3. Filling Out the D3DPRESENT_PARAMETERS Structure
	//this structure is used to specify some of the characteristics of the IDirect3DDevice9
	D3DPRESENT_PARAMETERS d3dpp;
	d3dpp.BackBufferWidth               = 800;
	d3dpp.BackBufferHeight              = 600;
	d3dpp.BackBufferFormat              = D3DFMT_A8R8G8B8; // pixel format
	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; // depth format
	d3dpp.Flags                      = 0;
	d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
	d3dpp.PresentationInterval       = D3DPRESENT_INTERVAL_IMMEDIATE;

	HRESULT hr = _d3d9->CreateDevice(
		D3DADAPTER_DEFAULT,
		deviceType,
		hWnd,
		D3DCREATE_HARDWARE_VERTEXPROCESSING,
		&d3dpp,
		&g_pd3dDevice
		);

	if(hr != S_OK)
	{
		::MessageBox(0, "CreateDevice() - FAILED", 0, 0);
		return 0;
	}

	return hr;

}
void Cleanup()
{

}
void Render()
{
	if( g_pd3dDevice )
	{
		g_pd3dDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
			0x00000000, 1.0f, 0);
		g_pd3dDevice->Present(0, 0, 0, 0);// present backbuffer
	}
	return ;

}
HRESULT InitVB()
{
	return 0;
}
void SetupMatrices()
{

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值