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

天行健 君子當(dāng)自強(qiáng)而不息

Direct3D中的字體與文本顯示(1)

圖形系統(tǒng)中為了獲得當(dāng)前運(yùn)行程序的相關(guān)信息,往往需要在屏幕上顯示文本,Direct3D的功能擴(kuò)展接口ID3DXFont對此提供了方便的解決方法。

 

創(chuàng)建ID3DXFont對象

使用接口ID3DXFont繪制文本,首先需要通過函數(shù)D3DXCreateFont()創(chuàng)建ID3DXFont字體對象。ID3DXFont接口封裝了Windows字體和Direct3D設(shè)備指針,D3DXCreateFont()函數(shù)通過Windows字體和Direct3D設(shè)備指針創(chuàng)建ID3DXFont對象,該函數(shù)的聲明如下:

Creates a font object for a device and font.

HRESULT D3DXCreateFont(
LPDIRECT3DDEVICE9 pDevice,
INT Height,
UINT Width,
UINT Weight,
UINT MipLevels,
BOOL Italic,
DWORD CharSet,
DWORD OutputPrecision,
DWORD Quality,
DWORD PitchAndFamily,
LPCTSTR pFacename,
LPD3DXFONT * ppFont
);

Parameters

pDevice
[in] Pointer to an IDirect3DDevice9 interface, the device to be associated with the font object.
Height
[in] The height of the characters in logical units.
Width
[in] The width of the characters in logical units.
Weight
[in] Typeface weight. One example is bold.
MipLevels
[in] The number of mipmap levels.
Italic
[in] True for italic font, false otherwise.
CharSet
[in] The character set of the font.
OutputPrecision
[in] Specifies how Windows should attempt to match the desired font sizes and characteristics with actual fonts. Use OUT_TT_ONLY_PRECIS for instance, to ensure that you always get a TrueType font.
Quality
[in] Specifies how Windows should match the desired font with a real font. It applies to raster fonts only and should not affect TrueType fonts.
PitchAndFamily
[in] Pitch and family index.
pFacename
[in] String containing the typeface name. If the compiler settings require Unicode, the data type LPCTSTR resolves to LPCWSTR. Otherwise, the string data type resolves to LPCSTR. 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 S_OK. If the function fails, the return value can be one of the following: D3DERR_INVALIDCALL, D3DXERR_INVALIDDATA, E_OUTOFMEMORY.

Remarks

The creation of an ID3DXFont object requires that the device supports 32-bit color.

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

If you want more information about font parameters, see The Logical Font.

示例代碼如下:

D3DXCreateFont(g_device, 50, 20, 20, 0, FALSE, DEFAULT_CHARSET, 0, 0, 0, "Arial", &g_font);

 

使用ID3DXFont對象繪制二維文本

創(chuàng)建了ID3DXFont對象后,就可以使用其接口函數(shù)ID3DXFont::DrawText()在指定位置繪制二維文本,該函數(shù)支持ANSI和雙字節(jié)字符串,聲明如下:

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();

 

ID3DXFont其他相關(guān)接口函數(shù)

函數(shù)ID3DXFont::GetDevice()能夠獲得與ID3DXFont相關(guān)聯(lián)的Direct3D設(shè)備指針,該函數(shù)聲明如下:

Retrieves the Direct3D device associated with the font object.

HRESULT GetDevice(
LPDIRECT3DDEVICE9 * ppDevice
);

Parameters

ppDevice
[out] Address of a pointer to an IDirect3DDevice9 interface, representing the Direct3D device object associated with the font object.

Return Values

If the method succeeds, the return value is S_OK. If the method fails, the return value can be one of the following: D3DERR_INVALIDCALL, D3DXERR_INVALIDDATA.

Remarks

Note    Calling this method will increase the internal reference count on the IDirect3DDevice9 interface. Be sure to call IUnknown when you are done using this IDirect3DDevice9 interface or you will have a memory leak.

 

示例截圖:

 

源程序:

#include <D3D9.h>
#include 
<D3DX9Core.h>

#pragma warning(disable : 
4127)

#define CLASS_NAME    "GameApp"

#define release_com(p)    do { if(p) { (p)->Release(); (p) = NULL; } } while(0)

IDirect3D9
*                g_d3d;
IDirect3DDevice9
*        g_device;
ID3DXFont
*                g_font;

RECT                    g_client_rect;
const char*                g_text = "Welcome to Direct3D!";

bool init_d3d(HWND hwnd)
{
    g_d3d 
= Direct3DCreate9(D3D_SDK_VERSION);

    
if(g_d3d == NULL)
        
return false;

    D3DPRESENT_PARAMETERS d3dpp;
    ZeroMemory(
&d3dpp, sizeof(d3dpp));

    d3dpp.Windowed            
= TRUE;
    d3dpp.SwapEffect        
= D3DSWAPEFFECT_DISCARD;
    d3dpp.BackBufferFormat    
= D3DFMT_UNKNOWN;

    
if(FAILED(g_d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                                  
&d3dpp, &g_device)))
    {
        
return false;
    }

    
/*
    D3DXCreateFontA(
        LPDIRECT3DDEVICE9       pDevice,  
        INT                     Height,
        UINT                    Width,
        UINT                    Weight,
        UINT                    MipLevels,
        BOOL                    Italic,
        DWORD                   CharSet,
        DWORD                   OutputPrecision,
        DWORD                   Quality,
        DWORD                   PitchAndFamily,
        LPCSTR                  pFaceName,
        LPD3DXFONT*             ppFont);
    
*/

    D3DXCreateFont(g_device, 
5020200, FALSE, DEFAULT_CHARSET, 000"Arial"&g_font);
        
    GetClientRect(hwnd, 
&g_client_rect);

    
return true;
}

void cleanup()
{
    release_com(g_font);
    release_com(g_device);
    release_com(g_d3d);
}

void render()
{
    g_device
->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(555), 1.0f0);

    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();

    g_device
->Present(NULL, NULL, NULL, NULL);
}

LRESULT WINAPI WinProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    
switch(msg)
    {
    
case WM_KEYDOWN:
        
if(wParam == VK_ESCAPE)
            DestroyWindow(hwnd);
        
break;

    
case WM_DESTROY:        
        PostQuitMessage(
0);
        
return 0;
    }

    
return DefWindowProc(hwnd, msg, wParam, lParam);
}

int WINAPI WinMain(HINSTANCE inst, HINSTANCE, LPSTR, INT)
{
    WNDCLASSEX wc;

    wc.cbSize            
= sizeof(WNDCLASSEX);
    wc.style            
= CS_CLASSDC;
    wc.lpfnWndProc        
= WinProc;
    wc.cbClsExtra        
= 0;
    wc.cbWndExtra        
= 0;
    wc.hInstance        
= inst;
    wc.hIcon            
= NULL;
    wc.hCursor            
= NULL;
    wc.hbrBackground    
= NULL;
    wc.lpszMenuName        
= NULL;
    wc.lpszClassName    
= CLASS_NAME;
    wc.hIconSm            
= NULL;

    
if(! RegisterClassEx(&wc))
        
return -1;

    HWND hwnd 
= CreateWindow(CLASS_NAME, "Direct3D App", WS_OVERLAPPEDWINDOW, 200100600500,
                             NULL, NULL, wc.hInstance, NULL);

    
if(hwnd == NULL)
        
return -1;

    
if(init_d3d(hwnd))
    {
        ShowWindow(hwnd, SW_SHOWDEFAULT);
        UpdateWindow(hwnd);

        MSG msg;
        ZeroMemory(
&msg, sizeof(msg));

        
while(msg.message != WM_QUIT)
        {
            
if(PeekMessage(&msg, NULL, 00, PM_REMOVE))
            {
                TranslateMessage(
&msg);
                DispatchMessage(
&msg);
            }
                
            render();
            Sleep(
10);
        }
    }

    cleanup();

    UnregisterClass(CLASS_NAME, wc.hInstance);    

    
return 0;
}

 

posted on 2008-05-11 19:26 lovedday 閱讀(4569) 評(píng)論(0)  編輯 收藏 引用


只有注冊用戶登錄后才能發(fā)表評(píng)論。
網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


公告

導(dǎo)航

統(tǒng)計(jì)

常用鏈接

隨筆分類(178)

3D游戲編程相關(guān)鏈接

搜索

最新評(píng)論

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            玖玖玖免费嫩草在线影院一区| 午夜电影亚洲| 欧美视频二区36p| 欧美精品日韩www.p站| 欧美电影免费观看高清| 欧美成人a视频| 欧美激情导航| 国产精品任我爽爆在线播放| 国产精品欧美日韩久久| 韩国av一区二区| 在线观看三级视频欧美| 亚洲激情成人网| 午夜久久福利| 欧美成人dvd在线视频| 最新精品在线| 亚洲午夜久久久久久尤物| 欧美在线观看视频在线| 久久xxxx| 欧美日产在线观看| 国产性天天综合网| 日韩视频精品在线| 欧美一区二区免费视频| 免费久久久一本精品久久区| 亚洲美女色禁图| 欧美一级久久久| 欧美激情久久久久| 国产欧美一区二区三区国产幕精品| 一区视频在线看| 午夜久久福利| 亚洲人成在线观看网站高清| 午夜精品久久| 欧美体内she精视频| 在线不卡免费欧美| 一区久久精品| 国产精品成人一区二区| 国内揄拍国内精品久久| 日韩视频专区| 久久综合精品国产一区二区三区| 亚洲美女免费精品视频在线观看| 久久综合电影| 国产一区二区中文| 亚洲欧美综合另类中字| 日韩一区二区高清| 狂野欧美一区| 一区二区三区在线视频播放| 性色av香蕉一区二区| 亚洲国产精品尤物yw在线观看| 欧美一区二区三区啪啪| 欧美日韩hd| 在线一区二区三区四区| 亚洲肉体裸体xxxx137| 美玉足脚交一区二区三区图片| 国产日产欧美一区| 欧美伊人久久久久久午夜久久久久 | 一本色道久久88精品综合| 久久久人成影片一区二区三区观看 | 亚洲精品一级| 亚洲高清免费| 免费短视频成人日韩| 18成人免费观看视频| 久久亚洲私人国产精品va| 欧美一区二区三区在| 国产亚洲精品一区二区| 久久亚洲精品一区二区| 久久精品动漫| 精品电影一区| 欧美国产一区二区三区激情无套| 久久精品成人欧美大片古装| 国产一区二区三区在线观看免费视频| 欧美夜福利tv在线| 亚洲欧美国产毛片在线| 国产中文一区二区| 狂野欧美激情性xxxx欧美| 久久久久www| 亚洲美女免费视频| 一本不卡影院| 国产亚洲欧美日韩精品| 理论片一区二区在线| 久久亚洲影音av资源网| 99这里有精品| 亚洲欧美激情视频| 在线看国产一区| 日韩性生活视频| 国产欧美韩日| 亚洲观看高清完整版在线观看| 欧美日韩黄色大片| 久久精品视频99| 欧美成年人视频网站欧美| 欧美国产欧美亚洲国产日韩mv天天看完整| 久久久久久91香蕉国产| 亚洲精品国精品久久99热一| 亚洲精品乱码久久久久久黑人 | 欧美国产日韩一区二区三区| 欧美久久99| 久久嫩草精品久久久精品| 久久久久久久欧美精品| 亚洲视频欧美在线| 久久狠狠亚洲综合| av成人福利| 久久久人成影片一区二区三区 | 欧美**人妖| 欧美一区国产一区| 欧美二区在线播放| 久久久www成人免费无遮挡大片 | 欧美影院在线| 9人人澡人人爽人人精品| 欧美中文在线观看国产| 99精品国产福利在线观看免费| 亚洲欧美视频在线| 99视频超级精品| 久久伊人一区二区| 亚洲欧美视频在线观看视频| 麻豆91精品| 久久婷婷国产麻豆91天堂| 欧美午夜免费电影| 亚洲精品一二三| 亚洲精品色图| 久久最新视频| 母乳一区在线观看| 好吊成人免视频| 欧美在线短视频| 久久本道综合色狠狠五月| 欧美人在线观看| 亚洲激情另类| 91久久久亚洲精品| 美女露胸一区二区三区| 老鸭窝亚洲一区二区三区| 国产午夜一区二区三区| 午夜精品久久久久久久99热浪潮| 亚洲午夜一二三区视频| 欧美日本韩国| 亚洲伦理网站| 亚洲视频1区| 国产精品豆花视频| 亚洲午夜免费视频| 先锋影音久久久| 国产伦精品一区二区三区| 亚洲一区免费| 久久久噜噜噜久久中文字免| 国产亚洲欧洲| 久久国产一二区| 久久久无码精品亚洲日韩按摩| 国产精品永久入口久久久| 亚洲日本久久| 欧美在线视频导航| 欧美色图一区二区三区| 亚洲电影免费观看高清| 亚洲激情不卡| 欧美成人自拍视频| 亚洲欧洲中文日韩久久av乱码| 亚洲国产日韩一级| 久久久精品国产免费观看同学| 老司机免费视频一区二区| 伊伊综合在线| 欧美国产日韩xxxxx| 亚洲国产美女| 亚洲一区免费在线观看| 国产精品久久| 欧美亚洲一区二区三区| 久久一区二区视频| 亚洲欧洲日产国产综合网| 欧美日韩不卡视频| 亚洲欧美日韩精品久久亚洲区 | 亚洲国产高清一区| 亚洲影院污污.| 国产三区精品| 欧美成人激情在线| 中文国产一区| 久久亚洲春色中文字幕| av成人天堂| 国产一区二区av| 欧美日韩视频在线一区二区| 亚洲专区一二三| 欧美国产高潮xxxx1819| 亚洲欧美伊人| 亚洲高清免费视频| 国产精品在线看| 女人香蕉久久**毛片精品| 亚洲视频在线看| 欧美国产日韩一区二区三区| 亚洲欧美日韩区| 亚洲人屁股眼子交8| 国产精品都在这里| 欧美激情精品| 欧美在线一区二区| 在线视频欧美一区| 欧美激情在线免费观看| 欧美一级艳片视频免费观看| 亚洲理论在线观看| 国产乱理伦片在线观看夜一区| 欧美jizzhd精品欧美喷水 | 亚洲欧美激情四射在线日 | 国产精品久久久久久久久久ktv| 久久久精品动漫| 亚洲视频在线一区| 亚洲国产一区二区三区青草影视| 久久久久久亚洲精品杨幂换脸| 99国产精品一区| 亚洲午夜一区二区三区| 欧美高清一区|