青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

天行健 君子當自強而不息

D3D中的字體繪制(1)

9.1 ID3DXFont

在D3DX庫中提供了一個ID3DXFont接口,它能被用于在Direct3D應用程序中繪制文字。

9.1.1創建一個ID3DXFont

我們能夠使用D3DXCreateFontIndirect函數來創建一個ID3DXFont接口。

Creates a font object indirectly for both a device and a font.

HRESULT D3DXCreateFontIndirect(
LPDIRECT3DDEVICE9 pDevice,
CONST D3DXFONT_DESC * pDesc,
LPD3DXFONT * ppFont
);

Parameters

pDevice
[in] Pointer to an IDirect3DDevice9 interface, the device to be associated with the font object.
pDesc
[in] Pointer to a D3DXFONT_DESC structure, describing the attributes of the font object to create. If the compiler settings require Unicode, the data type D3DXFONT_DESC resolves to D3DXFONT_DESCW; otherwise, the data type resolves to D3DXFONT_DESCA. See Remarks.
ppFont
[out] Returns a pointer to an ID3DXFont interface, representing the created font object.

Return Values

If the function succeeds, the return value is D3D_OK. If the function fails, the return value can be one of the following: D3DERR_INVALIDCALL, E_OUTOFMEMORY.

Remarks

The compiler setting also determines the function version. If Unicode is defined, the function call resolves to D3DXCreateFontIndirectW. Otherwise, the function call resolves to D3DXCreateFontIndirectA because ANSI strings are being used.

Defines the attributes of a font.

typedef struct D3DXFONT_DESC {
INT Height;
UINT Width;
UINT Weight;
UINT MipLevels;
BOOL Italic;
BYTE CharSet;
BYTE OutputPrecision;
BYTE Quality;
BYTE PitchAndFamily;
TCHAR FaceName[LF_FACESIZE];
} D3DXFONT_DESC, *LPD3DXFONT_DESC;

Members

Height
Height, in logical units, of the font's character cell or character.
Width
Width, in logical units, of characters in the font.
Weight
Weight of the font in the range from 0 through 1000.
MipLevels
Number of mip levels requested. If this value is zero or D3DX_DEFAULT, a complete mipmap chain is created. If the value is 1, the texture space is mapped identically to the screen space.
Italic
Set to TRUE for an Italic font.
CharSet
Character set.
OutputPrecision
Output precision. The output precision defines how closely the output must match the requested font height, width, character orientation, escapement, pitch, and font type.
Quality
Output quality.
PitchAndFamily
Pitch and family of the font.
FaceName
A null-terminated string or characters that specifies the typeface name of the font. The length of the string must not exceed 32 characters, including the terminating null character. If FaceName is an empty string, the first font that matches the other specified attributes will be used. If the compiler settings require Unicode, the data type TCHAR resolves to WCHAR; otherwise, the data type resolves to CHAR. See Remarks.

Remarks

The compiler setting also determines the structure type. If Unicode is defined, the D3DXFONT_DESC structure type resolves to a D3DXFONT_DESCW; otherwise the structure type resolves to a D3DXFONT_DESCA.

Possible values of the above members are given in the GDI LOGFONT structure.

下面的代碼片段顯示了怎樣使用這個函數:

    D3DXFONT_DESC font_desc;
    ZeroMemory(
&font_desc, sizeof(font_desc));

    font_desc.Height            
= 25;        // in logical units
    font_desc.Width                = 12;        // in logical units
    font_desc.Weight            = 500;        // boldness, range 0(light) - 1000(bold)
    font_desc.Italic            = FALSE;
    font_desc.CharSet            
= DEFAULT_CHARSET;
    font_desc.OutputPrecision    
= 0;
    font_desc.Quality            
= 0;
    font_desc.PitchAndFamily    
= 0;

    strcpy(font_desc.FaceName, 
"Times New Roman");

    
if(FAILED(D3DXCreateFontIndirect(g_d3d_device, &font_desc, &g_d3d_font)))
    {
        MessageBox(NULL, 
"D3DXCreateFontIndirect() - FAILED", NULL, MB_OK);
        PostQuitMessage(
0);
    }

 

注意:你也能夠使用D3DXCreateFont函數來獲得一個ID3DXFont接口指針。

9.1.2繪制文本

一旦我們獲得了ID3DXFont接口指針,繪制文本就是很簡單的事情了,我們只要調用ID3DXFont::DrawText方法就可以實現了。

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.

運行截圖:

主程序:

/**************************************************************************************
  Shows how to calculate the number of frames rendered per second and demonstrates 
  how to render text with the ID3DXFont interface.  
 *************************************************************************************
*/

#include 
<stdio.h>
#include 
"d3dUtility.h"

#pragma warning(disable : 
4100 4996)

const int WIDTH  = 640;
const int HEIGHT = 480;

IDirect3DDevice9
*        g_d3d_device;
ID3DXFont
*                g_d3d_font;

DWORD    g_frame_count;
float    g_time_elapsed;
float    g_fps;
char    g_fps_string[9];

////////////////////////////////////////////////////////////////////////////////////////////////////

bool setup()
{    
    D3DXFONT_DESC font_desc;
    ZeroMemory(
&font_desc, sizeof(font_desc));

    font_desc.Height            
= 25;        // in logical units
    font_desc.Width                = 12;        // in logical units
    font_desc.Weight            = 500;        // boldness, range 0(light) - 1000(bold)
    font_desc.Italic            = FALSE;
    font_desc.CharSet            
= DEFAULT_CHARSET;
    font_desc.OutputPrecision    
= 0;
    font_desc.Quality            
= 0;
    font_desc.PitchAndFamily    
= 0;

    strcpy(font_desc.FaceName, 
"Times New Roman");

    
if(FAILED(D3DXCreateFontIndirect(g_d3d_device, &font_desc, &g_d3d_font)))
    {
        MessageBox(NULL, 
"D3DXCreateFontIndirect() - FAILED", NULL, MB_OK);
        PostQuitMessage(
0);
    }
    
    
return true;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////

void cleanup()
{    
    safe_release
<ID3DXFont*>(g_d3d_font);    
}

///////////////////////////////////////////////////////////////////////////////////////////////////////

bool display(float time_delta)
{
    
// update: compute the frames per second.

    g_frame_count
++;
    g_time_elapsed 
+= time_delta;

    
if(g_time_elapsed >= 1.0f)
    {
        g_fps 
= g_frame_count / g_time_elapsed;

        sprintf(g_fps_string, 
"%f", g_fps);
        g_fps_string[
8= '\0';    // mark end of string

        g_time_elapsed 
= 0.0f;
        g_frame_count  
= 0;
    }

    
// render

    g_d3d_device
->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff1.0f0);

    g_d3d_device
->BeginScene();

    RECT rect 
= {00, WIDTH, HEIGHT};
    g_d3d_font
->DrawText(NULL, g_fps_string, -1&rect, DT_TOP | DT_LEFT, 0xff000000);

    g_d3d_device
->EndScene();

    g_d3d_device
->Present(NULL, NULL, NULL, NULL);

    
return true;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////

LRESULT CALLBACK wnd_proc(HWND hwnd, UINT msg, WPARAM word_param, LPARAM long_param)
{
    
switch(msg)
    {
    
case WM_DESTROY:
        PostQuitMessage(
0);
        
break;

    
case WM_KEYDOWN:
        
if(word_param == VK_ESCAPE)
            DestroyWindow(hwnd);
        
break;
    }

    
return DefWindowProc(hwnd, msg, word_param, long_param);
}

///////////////////////////////////////////////////////////////////////////////////////////////////////

int WINAPI WinMain(HINSTANCE inst, HINSTANCE, PSTR cmd_line, int cmd_show)
{
    
if(! init_d3d(inst, WIDTH, HEIGHT, true, D3DDEVTYPE_HAL, &g_d3d_device))
    {
        MessageBox(NULL, 
"init_d3d() - failed."0, MB_OK);
        
return 0;
    }

    
if(! setup())
    {
        MessageBox(NULL, 
"Steup() - failed."0, MB_OK);
        
return 0;
    }

    enter_msg_loop(display);

    cleanup();
    g_d3d_device
->Release();

    
return 0;
}

 

下載源程序

posted on 2008-03-26 16:50 lovedday 閱讀(3275) 評論(0)  編輯 收藏 引用


只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


公告

導航

統計

常用鏈接

隨筆分類(178)

3D游戲編程相關鏈接

搜索

最新評論

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            亚洲国产一区二区三区青草影视 | 亚洲视频每日更新| 一个色综合导航| 久久久亚洲欧洲日产国码αv| 欧美日韩理论| 国产日韩精品一区二区| 99视频热这里只有精品免费| 久久人人爽人人爽爽久久| av不卡在线| 欧美精品v日韩精品v韩国精品v| 国产尤物精品| 欧美亚洲综合另类| 亚洲视频一区在线| 欧美日韩在线看| 日韩一区二区精品视频| 欧美电影免费观看高清| 久久久久九九视频| 国产在线麻豆精品观看| 99精品99| 欧美超级免费视 在线| 久久精品国产99国产精品澳门| 国产美女高潮久久白浆| 欧美一区二区在线免费观看| 一区二区三区四区国产精品| 欧美日韩精品免费观看视一区二区| 最近中文字幕mv在线一区二区三区四区 | 欧美国产亚洲精品久久久8v| 欧美怡红院视频| 亚洲影院污污.| 国产目拍亚洲精品99久久精品| 亚洲在线视频免费观看| 一本色道久久综合狠狠躁篇的优点| 欧美三区免费完整视频在线观看| 国产精品99久久久久久www| 亚洲欧洲精品天堂一级| 欧美日韩 国产精品| 亚洲一区二区日本| 午夜欧美理论片| 在线观看视频免费一区二区三区| 欧美xxx成人| 欧美日韩视频在线一区二区 | 亚洲丁香婷深爱综合| 亚洲第一免费播放区| 欧美日韩另类在线| 欧美中文字幕久久| 麻豆久久婷婷| 亚洲免费中文| 久久嫩草精品久久久精品| 亚洲久久在线| 午夜欧美精品| 国产亚洲美州欧州综合国| 免费看成人av| 欧美三级免费| 久久影院亚洲| 欧美色图天堂网| 久久午夜精品| 欧美日韩一区二区三区在线观看免| 亚洲主播在线播放| 久久久久久久成人| 亚洲精选视频免费看| 一区二区三区你懂的| 尤物yw午夜国产精品视频明星| 亚洲精品系列| 黄色成人91| 亚洲视频axxx| 日韩视频在线一区二区| 亚洲一区二区三区777| 亚洲人精品午夜| 欧美在线日韩在线| 一本色道久久88综合日韩精品 | 国产精品久久久久久久电影 | 久久精品九九| 亚洲欧美日韩在线综合| 蜜臀a∨国产成人精品| 欧美一区二区三区视频免费播放 | 欧美视频在线观看 亚洲欧| 老司机久久99久久精品播放免费| 国产精品99一区二区| 亚洲国产精品热久久| 国产在线不卡精品| 国产精品色在线| 亚洲欧洲日产国产综合网| 国产精品私房写真福利视频| 91久久精品一区二区三区| 亚洲国产成人91精品| 欧美国产一区在线| 狠狠色狠狠色综合日日五| 亚洲在线一区二区三区| 在线亚洲一区观看| 欧美久久婷婷综合色| 欧美激情视频一区二区三区不卡| 国产精品日韩欧美一区二区| 日韩视频不卡| 在线一区免费观看| 欧美精品在线一区二区| 亚洲国产精品第一区二区| 亚洲国产日韩欧美在线图片| 久久黄金**| 免费av成人在线| 在线欧美日韩精品| 久久精品一区四区| 免费毛片一区二区三区久久久| 精品不卡在线| 久久久精品五月天| 欧美大胆成人| 亚洲九九爱视频| 欧美揉bbbbb揉bbbbb| 一本综合精品| 欧美中文字幕视频| 狠狠色丁香久久婷婷综合丁香| 久久久av毛片精品| 亚洲国产mv| 亚洲一区www| 国产日韩在线亚洲字幕中文| 午夜一级久久| 女仆av观看一区| 亚洲毛片在线免费观看| 欧美日本二区| 亚洲自拍另类| 老司机67194精品线观看| 亚洲国产精品第一区二区三区| 欧美www视频| 一区二区三区久久网| 久久福利毛片| 亚洲国产综合视频在线观看| 欧美日韩a区| 欧美亚洲免费高清在线观看| 欧美不卡激情三级在线观看| 午夜精品视频在线观看| 欧美日韩中文| 久久精品欧美日韩| 亚洲精品国产精品乱码不99 | 久久免费99精品久久久久久| 影音先锋欧美精品| 欧美日本高清视频| 欧美在线日韩| 亚洲人在线视频| 欧美制服丝袜| 99在线观看免费视频精品观看| 国产精品青草久久| 美女视频黄 久久| 亚洲视频久久| 亚洲国产欧美一区| 欧美一区影院| 亚洲精品一区二区三区婷婷月 | 亚洲精品国产精品乱码不99| 国产精品v亚洲精品v日韩精品| 久久亚洲二区| 日韩午夜黄色| 国产一区二区三区高清在线观看 | 欧美日韩福利在线观看| 午夜精品三级视频福利| 亚洲第一成人在线| 欧美在线观看视频一区二区| 亚洲精选中文字幕| 国产一区欧美| 国产精品久久久久天堂| 欧美mv日韩mv国产网站| 先锋a资源在线看亚洲| 日韩视频在线观看免费| 欧美大胆a视频| 开心色5月久久精品| 亚洲欧美日韩在线播放| 一本色道久久综合亚洲精品按摩| 韩日欧美一区二区三区| 国产乱码精品一区二区三区忘忧草| 欧美国产日韩免费| 久久一区国产| 欧美国产第一页| 在线亚洲免费视频| 9人人澡人人爽人人精品| 欧美不卡在线视频| 美女免费视频一区| 久久久噜噜噜久久狠狠50岁| 午夜国产欧美理论在线播放| 亚洲一区二区三区精品在线| 亚洲精品一二区| 亚洲精品三级| 日韩视频在线一区二区| 亚洲精品护士| 亚洲另类黄色| 最新高清无码专区| 亚洲国产天堂久久国产91| 在线不卡免费欧美| 在线看成人片| 亚洲经典自拍| 亚洲精品欧洲精品| 亚洲人午夜精品免费| 在线观看一区视频| 亚洲欧美日韩一区在线观看| 亚洲综合日韩在线| 亚洲在线一区二区三区| 亚洲欧美日韩直播| 午夜久久久久久| 久久久亚洲人| 女生裸体视频一区二区三区| 欧美成人乱码一区二区三区| 欧美激情一二区| 欧美四级在线| 国产一区二区日韩精品欧美精品|