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

天行健 君子當自強而不息

D3D中的字體繪制示例

技巧如下:

字體的繪制需要使用ID3DXFont對象和 D3DXCreateFontIndirect函數。

DirectX SDK文檔對ID3DXFont做了簡要的說明:

The ID3DXFont interface encapsulates the textures and resources needed to render a specific font on a specific device.

The ID3DXFont interface is obtained by calling D3DXCreateFont or D3DXCreateFontIndirect.

我們來看看SDK文檔提供的關于 D3DXCreateFontIndirect的使用說明:

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.

該函數的第二個參數使用了一個結構體D3DXFONT_DESC,來看看它的具體定義:

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;

   // create the font
    ZeroMemory(&font_desc, sizeof(font_desc));
    
    
// set font descripter
    strcpy(font_desc.FaceName, "Arial");
    font_desc.Height = 32;

    
// Creates a font object indirectly for both a device and a font
    D3DXCreateFontIndirect(g_d3d_device, &font_desc, &g_font);

通過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.


我們可以這樣使用該函數:

    RECT rect = { 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT };

    // Begin scene
    if(SUCCEEDED(g_d3d_device->BeginScene()))
    {
        
// draw some text
        g_font->DrawTextA(NULL, "Programming is fun!", -1, &rect, DT_CENTER | DT_VCENTER, 0xFFFFFFFF);

        
// end the scene
        g_d3d_device->EndScene();
    }

完整源碼如下:

 
/***************************************************************************************
PURPOSE:
    Font Demo

Required libraries:
  D3D9.LIB and D3DX9.LIB
 ***************************************************************************************/


#include <windows.h>
#include <stdio.h>
#include "d3d9.h"
#include "d3dx9.h"

#pragma comment(lib, "d3d9.lib")
#pragma comment(lib, "d3dx9.lib")

#pragma warning(disable : 4996)

#define WINDOW_WIDTH    400
#define WINDOW_HEIGHT   400

#define Safe_Release(p) if((p)) (p)->Release();

// window handles, class and caption text.
HWND g_hwnd;
HINSTANCE g_inst;
static char g_class_name[] = "FontClass";
static char g_caption[]    = "Font Demo";

// the Direct3D and device object
IDirect3D9* g_d3d = NULL;
IDirect3DDevice9* g_d3d_device = NULL;

// the font object
ID3DXFont* g_font = NULL;

//--------------------------------------------------------------------------------
// Window procedure.
//--------------------------------------------------------------------------------
long WINAPI Window_Proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    
switch(msg)
    {
    
case WM_DESTROY:
        PostQuitMessage(0);
        
return 0;
    }

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

//--------------------------------------------------------------------------------
// Initialize d3d, d3d device, vertex buffer, texutre. 
//--------------------------------------------------------------------------------
BOOL Do_Init()
{
    D3DPRESENT_PARAMETERS   present_param;
    D3DDISPLAYMODE          display_mode;
    D3DXFONT_DESC           font_desc;

    
// do a windowed mode initialization of Direct3D
    if((g_d3d = Direct3DCreate9(D3D_SDK_VERSION)) == NULL)
        
return FALSE;

    
// retrieves the current display mode of the adapter
    if(FAILED(g_d3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &display_mode)))
        
return FALSE;

    ZeroMemory(&present_param, 
sizeof(present_param));

    
// initialize d3d presentation parameter
    present_param.Windowed          = TRUE;
    present_param.SwapEffect        = D3DSWAPEFFECT_DISCARD;
    present_param.BackBufferFormat  = display_mode.Format;    

    
// creates a device to represent the display adapter
    if(FAILED(g_d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, g_hwnd,
                                  D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_param, &g_d3d_device)))
        
return FALSE;     

    
// create the font
    ZeroMemory(&font_desc, sizeof(font_desc));
    
    
// set font descripter
    strcpy(font_desc.FaceName, "Arial");
    font_desc.Height = 32;

    
// Creates a font object indirectly for both a device and a font
    D3DXCreateFontIndirect(g_d3d_device, &font_desc, &g_font);

    
return TRUE;
}

//--------------------------------------------------------------------------------
// Release all d3d resource.
//--------------------------------------------------------------------------------
BOOL Do_Shutdown()
{
    Safe_Release(g_font);
    Safe_Release(g_d3d_device);
    Safe_Release(g_d3d);

    
return TRUE;
}

//--------------------------------------------------------------------------------
// Render a frame.
//--------------------------------------------------------------------------------
BOOL Do_Frame()
{
    RECT rect = { 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT };

    
// clear device back buffer
    g_d3d_device->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_RGBA(0, 64, 128, 255), 1.0f, 0);

    
// Begin scene
    if(SUCCEEDED(g_d3d_device->BeginScene()))
    {
        
// draw some text
        g_font->DrawTextA(NULL, "Programming is fun!", -1, &rect, DT_CENTER | DT_VCENTER, 0xFFFFFFFF);

        
// end the scene
        g_d3d_device->EndScene();
    }

    
// present the contents of the next buffer in the sequence of back buffers owned by the device
    g_d3d_device->Present(NULL, NULL, NULL, NULL);

    
return TRUE;
}

//--------------------------------------------------------------------------------
// Main function, routine entry.
//--------------------------------------------------------------------------------
int WINAPI WinMain(HINSTANCE inst, HINSTANCE, LPSTR cmd_line, int cmd_show)
{
    WNDCLASSEX  win_class;
    MSG         msg;

    g_inst = inst;

    
// create window class and register it
    win_class.cbSize        = sizeof(win_class);
    win_class.style         = CS_CLASSDC;
    win_class.lpfnWndProc   = Window_Proc;
    win_class.cbClsExtra    = 0;
    win_class.cbWndExtra    = 0;
    win_class.hInstance     = inst;
    win_class.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
    win_class.hCursor       = LoadCursor(NULL, IDC_ARROW);
    win_class.hbrBackground = NULL;
    win_class.lpszMenuName  = NULL;
    win_class.lpszClassName = g_class_name;
    win_class.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);

    
if(! RegisterClassEx(&win_class))
        
return FALSE;

    
// create the main window
    g_hwnd = CreateWindow(g_class_name, g_caption, WS_CAPTION | WS_SYSMENU, 0, 0,
                          WINDOW_WIDTH, WINDOW_HEIGHT, NULL, NULL, inst, NULL);

    
if(g_hwnd == NULL)
        
return FALSE;

    ShowWindow(g_hwnd, SW_NORMAL);
    UpdateWindow(g_hwnd);

    
// initialize game
    if(Do_Init() == FALSE)
        
return FALSE;

    
// start message pump, waiting for signal to quit.
    ZeroMemory(&msg, sizeof(MSG));

    
while(msg.message != WM_QUIT)
    {
        
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
        
        
// draw a frame
        if(Do_Frame() == FALSE)
            
break;
    }

    
// run shutdown function
    Do_Shutdown();

    UnregisterClass(g_class_name, inst);
    
    
return (int) msg.wParam;
}
 

效果圖如下:



posted on 2007-07-03 19:33 lovedday 閱讀(3419) 評論(1)  編輯 收藏 引用 所屬分類: ■ DirectX 9 Program

評論

# re: D3D中的字體繪制示例 2007-08-20 15:01 RISE

不錯,支持了.  回復  更多評論   

公告

導航

統計

常用鏈接

隨筆分類(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>
            久久综合五月天婷婷伊人| 欧美在线视频免费播放| 欧美成人免费网| 亚洲黄一区二区| 亚洲国产精品久久久| 久久艳片www.17c.com| 在线不卡a资源高清| 久久久久国产精品午夜一区| 先锋影音国产一区| 国产一区二区三区在线观看精品 | 久久久99久久精品女同性| 亚洲欧美日韩国产| 国产综合色产| 欧美freesex8一10精品| 欧美va亚洲va香蕉在线| 日韩视频在线免费| 一本色道久久综合精品竹菊| 国产精品热久久久久夜色精品三区 | 欧美精品久久久久久久久老牛影院| 亚洲国产日韩一级| 日韩午夜激情电影| 国产精品亚洲аv天堂网 | 亚洲精品免费在线观看| 夜夜嗨网站十八久久| 国产精品一区久久| 免费短视频成人日韩| 欧美日韩国产成人| 欧美一区久久| 欧美顶级艳妇交换群宴| 亚洲一级特黄| 久久成人综合网| 国产精品99久久久久久久久久久久 | 欧美激情精品久久久六区热门| 欧美高清视频在线观看| 欧美影院午夜播放| 欧美激情区在线播放| 午夜一级久久| 欧美xart系列高清| 午夜精品视频| 欧美国产高清| 麻豆成人综合网| 国产精品久久久久毛片软件 | 久久人人爽爽爽人久久久| 欧美成人首页| 久久噜噜噜精品国产亚洲综合| 欧美精品国产| 欧美 日韩 国产精品免费观看| 国产精品福利在线观看网址| 亚洲成色www久久网站| 国产日韩欧美在线看| 亚洲日本视频| 亚洲精品乱码久久久久久黑人 | 亚洲高清久久久| 国产日韩欧美二区| 一区二区电影免费观看| 亚洲三级免费| 乱中年女人伦av一区二区| 久久av一区二区三区亚洲| 欧美日韩在线直播| 欧美国产在线电影| 在线观看av一区| 久久精品成人欧美大片古装| 欧美一区亚洲一区| 国产美女扒开尿口久久久| 亚洲视频你懂的| 亚洲在线播放电影| 欧美视频精品在线| 亚洲伦伦在线| 99国产精品视频免费观看一公开 | 欧美在线一区二区| 久久国内精品自在自线400部| 国产精品第十页| 中文一区字幕| 篠田优中文在线播放第一区| 国产精品区一区二区三| 亚洲制服欧美中文字幕中文字幕| 亚洲字幕一区二区| 国产精品一区二区三区久久久| 一区二区三区精品久久久| 亚洲一区二区免费在线| 国产精品国产三级欧美二区| 在线一区二区三区做爰视频网站| 亚洲图片欧美日产| 国产精品久久看| 性久久久久久久| 免费高清在线视频一区·| 在线日韩一区二区| 欧美激情精品久久久久久免费印度 | 午夜精品一区二区在线观看| 国产精品美腿一区在线看| 欧美一区日本一区韩国一区| 久久性色av| 亚洲精品1区2区| 欧美三级欧美一级| 羞羞视频在线观看欧美| 久久婷婷丁香| 日韩视频一区二区| 国产精品男人爽免费视频1| 欧美一区二区三区在线观看视频| 免费成人av在线| 亚洲图片你懂的| 伊人久久综合| 欧美另类变人与禽xxxxx| 亚洲欧美日韩精品在线| 欧美国产亚洲视频| 一区二区三区国产在线| 国产日韩欧美三级| 欧美大成色www永久网站婷| 一区二区三区|亚洲午夜| 久久久久成人网| 亚洲视频免费观看| 在线观看视频一区| 国产精品久久久久久久久久久久久| 欧美一区激情| 一本色道久久加勒比精品| 久久久蜜臀国产一区二区| 一本综合久久| 伊人色综合久久天天| 国产精品chinese| 蜜臀久久久99精品久久久久久| 日韩一区二区精品| 欧美不卡在线| 久久久福利视频| 亚洲一区二区黄色| 亚洲日本在线视频观看| 国产伊人精品| 国产精品人人爽人人做我的可爱| 欧美sm重口味系列视频在线观看| 亚洲男人第一网站| 一本一本久久a久久精品综合麻豆| 欧美阿v一级看视频| 久久久久久久999| 欧美一区二区黄| 一区二区国产日产| 亚洲人成网站777色婷婷| 国产在线欧美日韩| 国产欧美精品一区aⅴ影院| 欧美日韩 国产精品| 免费欧美视频| 可以看av的网站久久看| 久久riav二区三区| 午夜精品久久久久久久99樱桃| 一本大道av伊人久久综合| 亚洲国产精品va在线看黑人| 麻豆av一区二区三区| 久久午夜精品一区二区| 久久人人超碰| 美女国内精品自产拍在线播放| 久久久久久久成人| 久久视频国产精品免费视频在线 | 在线看日韩欧美| 韩国av一区二区| 国产主播精品| 精品福利免费观看| 在线观看亚洲视频| 亚洲国产欧美日韩精品| 在线日韩电影| 亚洲精品社区| 宅男噜噜噜66一区二区| 亚洲午夜国产一区99re久久| 国产精品99久久不卡二区| 亚洲一区黄色| 欧美一级大片在线免费观看| 欧美在线观看你懂的| 久久天天狠狠| 亚洲电影免费观看高清| 亚洲乱码视频| 亚洲无线一线二线三线区别av| 亚洲网站在线播放| 性欧美大战久久久久久久久| 久久精品国产77777蜜臀| 美女网站在线免费欧美精品| 欧美国产激情| 国产精品你懂的在线| 韩国三级电影久久久久久| 亚洲国产精品成人一区二区| 在线综合亚洲欧美在线视频| 欧美一级日韩一级| 欧美成人69av| 亚洲色在线视频| 久久久久久久综合日本| 欧美激情一区在线| 国产日韩欧美亚洲| 亚洲日本国产| 久久精品人人做人人爽电影蜜月 | 亚洲夜间福利| 久久久久一本一区二区青青蜜月| 欧美成人在线网站| 亚洲深夜福利视频| 久久久久久久久一区二区| 欧美久久成人| 永久免费视频成人| 亚洲一区激情| 亚洲第一精品久久忘忧草社区| 亚洲一级影院| 免费亚洲一区二区| 国产情侣久久| 亚洲午夜精品国产| 欧美 日韩 国产 一区| 亚洲欧美日韩国产一区二区|