ID3DXFont&&ID3DXSprite

 

ID3DXFont&&ID3DXSprite
2009-01-22 22:03

1:定义:ID3DXFont*                 g_pFont = NULL;  

2:创建对象:

HRESULT hr;

V_RETURN(D3DXCreateFont(pd3dDevice,15,0,FW_BOLD,0,FALSE,DEFAULT_CHARSET,
   OUT_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH|FF_DONTCARE,L"宋体",&g_pFont)) ;

参数含义:

1:设备指针2:字体逻辑高度3:逻辑宽度,取0使用默认4:字体的粗细,如word中的加粗。

5:字体过滤属性,一般取0. 6:是否为斜体7:字符集合8:指定字符输出精度 9:输出质量

10:字体索引号11:字体名称12:字体指针

3:宏V():返回错误hresult,必须在使用前的函数体里定义: HRESULT hr;

4:OnDestroyDevice中释放:

SAFE_RELEASE( g_pFont );

5: OnLostDevice中:

if( g_pFont )
        g_pFont->OnLostDevice();
    SAFE_RELEASE( g_pTextSprite );

6:void RenderText()
{
CDXUTTextHelper txtHelper( g_pFont, g_pTextSprite, 15 );

//显示当前Direct3D设备状态和渲染帧速率
txtHelper.Begin();
txtHelper.SetInsertionPos( 5, 5 );
txtHelper.SetForegroundColor( D3DXCOLOR( 1.0f, 1.0f, 0.0f, 1.0f ) );
txtHelper.DrawTextLine( DXUTGetFrameStats(true) );
txtHelper.DrawTextLine( DXUTGetDeviceStats() );

//显示其他简要信息
txtHelper.SetForegroundColor( D3DXCOLOR( 1.0f, 1.0f, 1.0f, 1.0f ) );
txtHelper.DrawTextLine( L"Put whatever misc status here" );

//显示简单帮助文本
const D3DSURFACE_DESC* pd3dsdBackBuffer = DXUTGetBackBufferSurfaceDesc();
   txtHelper.SetInsertionPos( 10, pd3dsdBackBuffer->Height-15*6 );
   txtHelper.SetForegroundColor( D3DXCOLOR( 1.0f, 0.75f, 0.0f, 1.0f ) );
   txtHelper.DrawTextLine( L"Controls (F1 to hide):" );

   txtHelper.SetInsertionPos( 40, pd3dsdBackBuffer->Height-15*5 );
   txtHelper.DrawTextLine( L"Quit: ESC" );

txtHelper.End();
}

7:OnFrameMove:

//渲染文本
   DXUT_BeginPerfEvent( DXUT_PERFEVENTCOLOR, L"HUD / Stats" );
   RenderText();
   DXUT_EndPerfEvent();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值