新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     W3CHINA.ORG讨论区     >>计算机科学论坛<<     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> 本版讨论高级C/C++编程、代码重构(Refactoring)、极限编程(XP)、泛型编程等话题
    [返回] 计算机科学论坛计算机技术与应用『 C/C++编程思想 』 → Direct3D中的字体与文本显示 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 11447 个阅读者浏览上一篇主题  刷新本主题   平板显示贴子 浏览下一篇主题
     * 贴子主题: Direct3D中的字体与文本显示 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     卷积内核 帅哥哟,离线,有人找我吗?
      
      
      威望:8
      头衔:总统
      等级:博士二年级(版主)
      文章:3942
      积分:27590
      门派:XML.ORG.CN
      注册:2004/7/21

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给卷积内核发送一个短消息 把卷积内核加入好友 查看卷积内核的个人资料 搜索卷积内核在『 C/C++编程思想 』的所有贴子 访问卷积内核的主页 引用回复这个贴子 回复这个贴子 查看卷积内核的博客楼主
    发贴心情 

    使用ID3DXFont对象绘制二维文本

    创建了ID3DXFont对象后,就可以使用其接口函数ID3DXFont::DrawText()在指定位置绘制二维文本,该函数支持ANSI和双字节字符串,声明如下:

    Draws formatted text. This method supports ANSI and Unicode strings.

    INT DrawText(  LPD3DXSPRITE pSprite,  LPCTSTR pString,  INT Count,  LPRECT pRect,  DWORD Format,  D3DCOLOR Color);
    Parameters
    pSprite
    [in] Pointer to an ID3DXSprite object that contains the string. Can be NULL, in which case Direct3D will render the string with its own sprite object. To improve efficiency, a sprite object should be specified if ID3DXFont::DrawText is to be called more than once in a row.
    pString
    [in] Pointer to a string to draw.If the Count parameter is -1, the string must be null-terminated.
    Count
    [in] Specifies the number of characters in the string. If Count is -1, then the pString parameter is assumed to be a pointer to a null-terminated string and ID3DXFont::DrawText computes the character count automatically.
    pRect
    [in] Pointer to a RECT structure that contains the rectangle, in logical coordinates, in which the text is to be formatted. As with any RECT object, the coordinate value of the rectangle's right side must be greater than that of its left side. Likewise, the coordinate value of the bottom must be greater than that of the top.
    Format
    [in] Specifies the method of formatting the text. It can be any combination of the following values:
    DT_BOTTOM
    Justifies the text to the bottom of the rectangle. This value must be combined with DT_SINGLELINE.
    DT_CALCRECT
    Determines the width and height of the rectangle. If there are multiple lines of text, ID3DXFont::DrawText uses the width of the rectangle pointed to by the pRect parameter and extends the base of the rectangle to bound the last line of text. If there is only one line of text, ID3DXFont::DrawText modifies the right side of the rectangle so that it bounds the last character in the line. In either case, ID3DXFont::DrawText returns the height of the formatted text but does not draw the text.
    DT_CENTER
    Centers text horizontally in the rectangle.
    DT_EXPANDTABS
    Expands tab characters. The default number of characters per tab is eight.
    DT_LEFT
    Aligns text to the left.
    DT_NOCLIP
    Draws without clipping. ID3DXFont::DrawText is somewhat faster when DT_NOCLIP is used.
    DT_RIGHT
    Aligns text to the right.
    DT_RTLREADING
    Displays text in right-to-left reading order for bidirectional text when a Hebrew or Arabic font is selected. The default reading order for all text is left-to-right.
    DT_SINGLELINE
    Displays text on a single line only. Carriage returns and line feeds do not break the line.
    DT_TOP
    Top-justifies text.
    DT_VCENTER
    Centers text vertically (single line only).
    DT_WORDBREAK
    Breaks words. Lines are automatically broken between words if a word would extend past the edge of the rectangle specified by the pRect parameter. A carriage return/line feed sequence also breaks the line.
    Color
    [in] Color of the text. For more information, see D3DCOLOR.
    Return Values
    If the function succeeds, the return value is the height of the text in logical units. If DT_VCENTER or DT_BOTTOM is specified, the return value is the offset from pRect (top to the bottom) of the drawn text. If the function fails, the return value is zero.

    Remarks
    The parameters of this method are very similar to those of the GDI DrawText function.

    This method supports both ANSI and Unicode strings.

    This method must be called inside a IDirect3DDevice9::BeginScene ... IDirect3DDevice9::EndScene block. The only exception is when an application calls ID3DXFont::DrawText with DT_CALCRECT to calculate the size of a given block of text.

    Unless the DT_NOCLIP format is used, this method clips the text so that it does not appear outside the specified rectangle. All formatting is assumed to have multiple lines unless the DT_SINGLELINE format is specified.

    If the selected font is too large for the rectangle, this method does not attempt to substitute a smaller font.

    This method supports only fonts whose escapement and orientation are both zero.

    示例代码如下:

    g_device->BeginScene();

    DWORD format = DT_SINGLELINE | DT_NOCLIP | DT_CENTER | DT_VCENTER;
    g_font->DrawText(NULL, g_text, (INT) strlen(g_text), &g_client_rect, format, 0xFFFFFF00);

    g_device->EndScene();

    ----------------------------------------------
    事业是国家的,荣誉是单位的,成绩是领导的,工资是老婆的,财产是孩子的,错误是自己的。

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2008/11/25 15:27:00
     
     GoogleAdSense
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 C/C++编程思想 』的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/5/10 8:49:03

    本主题贴数3,分页: [1]

     *树形目录 (最近20个回帖) 顶端 
    主题:  Direct3D中的字体与文本显示(2565字) - 卷积内核,2008年11月25日
        回复:  [B]ID3DXFont其他相关接口函数[/B]函数ID3DXFont::GetDevice(..(4873字) - 卷积内核,2008年11月25日
        回复:  使用ID3DXFont对象绘制二维文本创建了ID3DXFont对象后,就可以使用其接口函数ID..(4391字) - 卷积内核,2008年11月25日

    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    78.125ms