DirectX 3D_实践之DirectX3D中的文本绘制

本文档介绍了在Direct3D中以三种方式绘制文本,重点聚焦于使用D3DXCreateText函数创建并绘制3D文本。通过示例代码展示DirectX3D.h、DirectX3D.cpp和wmain.cpp中的实现,并讨论了不同文本绘制方法的性能特点,包括ID3DXFont接口的GDI绘制和CD3DFont类的快速绘制。
摘要由CSDN通过智能技术生成

                 最近的自己又开始有点浮躁,上班的时候,不知道干吗?归根结底还是,自己不够成熟。我应该慢慢的沉下来,争取详细的把整个文档,再仔细的梳理一遍。时刻提醒自己,越是动荡的时候,自己越是应该冷静下来。沉下去。相信自己,总有一天,我也会破茧成蝶,飞向成功。很喜欢,马云说过的一句话,十年,坚持一件事,十年如一日,你必成功。

 

               今天我们来看一下,Direct3D中的字体,我们有几种方式来绘制文本:

 

                1,通过ID3DXFont接口绘制文本。

                2,通过CD3DFont类绘制文本。

               3, 通过D3DXCreateText函数创建并绘制3D文本。

 

               这里,我们使用第3中方式来演示:

 

首先还是来看下DirectX3D.h的代码:

#ifndef __DirectX3DH__
#define __DirectX3DH__

#include <d3dx9.h>
#include <string>

namespace d3d
{
	bool InitD3D(
		HINSTANCE hInstance,       // [in] Application instance.
		int width, int height,     // [in] Backbuffer dimensions.
		bool windowed,             // [in] Windowed (true)or full screen (false).
		D3DDEVTYPE deviceType,     // [in] HAL or REF
		IDirect3DDevice9** device);// [out]The created device.
	
	int EnterMsgLoop( 
		bool (*ptr_display)(float timeDelta));
	
	LRESULT CALLBACK WndProc(
		HWND hwnd,
		UINT msg, 
		WPARAM wParam,
		LPARAM lParam);
	
	template<class T> void Release(T t)
	{
		if( t )
		{
			t->Release();
			t = 0;
		}
	}
	
	template<class T> void Delete(T t)
	{
		if( t )
		{
			delete t;
			t = 0;
		}
	}
	
	const D3DXCOLOR      WHITE( D3DCOLOR_XRGB(255, 255, 255) );
	const D3DXCOLOR      BLACK( D3DCOLOR_XRGB(  0,   0,   0) );
	const D3DXCOLOR        RED( D3DCOLOR_XRGB(255,   0,   0) );
	const D3DXCOLOR      GREEN( D3DCOLOR_XRGB(  0, 255,   0) );
	const D3DXCOLOR       BLUE( D3DCOLOR_XRGB(  0,   0, 255) );
	const D3DXCOLOR     YELLOW( D3DCOLOR_XRGB(255, 255,   0) );
	const D3DXCOLOR       CYAN( D3DCOLOR_XRGB(  0, 255, 255) );
	const D3DXCOLOR    MAGENTA( D3DCOLOR_XRGB(255,   0, 255) );
	
	//
	// Lights
	//
	
	D3DLIGHT9 InitDirectionalLight(D3DXVECTOR3* direction, D3DXCOLOR* color);
	D3DLIGHT9 InitPointLight(D3DXVECTOR3* position, D3DXCOLOR* color);
	D3DLIGHT9 InitSpotLight(D3DXVECTOR3* position, D3DXVECTOR3* direction, D3DXCOLOR* color);
	
	//
	// Materials
	//
	
	D3DMATERIAL9 InitMtrl(D3DXCOLOR a, D3DXCOLOR d, D3DXCOLOR s, D3DXCOLOR e, float p);
	
	const D3DMATERIAL9 WHITE_MTRL  = InitMtrl(WHITE, WHITE, WHITE, BLACK, 2.0f);
	const D3DMATERIAL9 RED_MTRL    = InitMtrl(RED, RED, RED, BLACK, 2.0f);
	const D3DMATERIAL9 GREEN_MTRL  = InitMtrl(GREEN, GREEN, GREEN, BLACK, 2.0f);
	const D3DMATERIAL9 BLUE_MTRL   = InitMtrl(BLUE, BLUE, BLUE, BLACK, 2.0f);
	const D3DMATERIAL9 YELLOW_MTRL = InitMtrl(YELLOW, YELLOW, YELLOW, BLACK, 2.0f);	

}




#endif 


再来看下,DirectX3D.cpp中的代码:

#include "DirectX3D.h"






bool d3d::InitD3D(
	HINSTANCE hInstance,
	int width, int height,
	bool 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值