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

天行健 君子當自強而不息

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

創(chuàng)建三維文本網格模型

在Direct3D中,三維物體的顯示是通過網格模型來實現的,顯示三維物體的關鍵在于生成該網格模型。三維文本也不例外,顯示三維文本同樣需要該文本所對應的網格模型。 Direct3D為此提供了功能庫函數D3DXCreateText(),通過它可以方便地創(chuàng)建一個包含具體文本的網格模型,該函數的聲明如下:

Creates a mesh containing the specified text, using the font associated with the device context.

HRESULT D3DXCreateText(
LPDIRECT3DDEVICE9 pDevice,
HDC hDC,
LPCTSTR pText,
FLOAT Deviation,
FLOAT Extrusion,
LPD3DXMESH * ppMesh,
LPD3DXBUFFER * ppAdjacency,
LPGLYPHMETRICSFLOAT pGlyphMetrics
);

Parameters

pDevice
[in] Pointer to the device that created the mesh.
hDC
[in] Device context, containing the font for output. The font selected by the device context must be a TrueType font.
pText
[in] Pointer to a string that specifies the text to generate. If the compiler settings require Unicode, the data type LPCTSTR resolves to LPCWSTR. Otherwise, the string data type resolves to LPCSTR. See Remarks.
Deviation
[in] Maximum chordal deviation from TrueType font outlines.
Extrusion
[in] Amount to extrude text in the negative z-direction.
ppMesh
[out] Pointer to the returned mesh.
ppAdjacency
[out] Pointer to a buffer containing adjacency information. May be NULL.
pGlyphMetrics
[out] Pointer to an array of GLYPHMETRICSFLOAT structures that contain the glyph metric data. Each element contains information about the position and orientation of the corresponding glyph in the string. The number of elements in the array should be equal to the number of characters in the string. Note that the origin in each structure is not relative to the entire string, but rather is relative to that character cell. To compute the entire bounding box, add the increment for each glyph while traversing the string. If you are not concerned with the glyph sizes, set this parameter to NULL.

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, D3DXERR_INVALIDDATA, E_OUTOFMEMORY.

Remarks

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

This function creates a mesh with the D3DXMESH_MANAGED creation option and D3DFVF_XYZ | D3DFVF_NORMAL flexible vertex format (FVF).

Deviaton指定弦偏差的最大值。

Extrusion指定文本在z軸負方向突出的總量。

GLYPHMETRICSFLOAT

The GLYPHMETRICSFLOAT structure contains information about the placement and orientation of a glyph in a character cell.

typedef struct _GLYPHMETRICSFLOAT { // gmf   
FLOAT gmfBlackBoxX;
FLOAT gmfBlackBoxY;
POINTFLOAT gmfptGlyphOrigin;
FLOAT gmfCellIncX;
FLOAT gmfCellIncY;
} GLYPHMETRICSFLOAT;

Members

gmfBlackBoxX
Specifies the width of the smallest rectangle (the glyph's black box) that completely encloses the glyph.
gmfBlackBoxY
Specifies the height of the smallest rectangle (the glyph's black box) that completely encloses the glyph.
gmfptGlyphOrigin
Specifies the x and y coordinates of the upper-left corner of the smallest rectangle that completely encloses the glyph.
gmfCellIncX
Specifies the horizontal distance from the origin of the current character cell to the origin of the next character cell.
gmfCellIncY
Specifies the vertical distance from the origin of the current character cell to the origin of the next character cell.

Remarks

The values of GLYPHMETRICSFLOAT are specified as notional units.

示例代碼如下:

	HDC hdc = CreateCompatibleDC(NULL);
if(hdc == NULL)
return false;
	HFONT hfont = CreateFont(0, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, L"Arial");
	SelectObject(hdc, hfont);
	D3DXCreateText(g_device, hdc, L"三維字體", 0.001f, 0.4f, &g_text_mesh, NULL, NULL);
	DeleteObject(hfont);
DeleteDC(hdc);

The CreateCompatibleDC function creates a memory device context (DC) compatible with the specified device.

HDC CreateCompatibleDC(
HDC
hdc // handle to DC
);

Parameters

hdc
[in] Handle to an existing DC. If this handle is NULL, the function creates a memory DC compatible with the application's current screen.

Return Values

If the function succeeds, the return value is the handle to a memory DC.

If the function fails, the return value is NULL.

Windows NT/2000/XP: To get extended error information, call GetLastError.

Remarks

A memory DC exists only in memory. When the memory DC is created, its display surface is exactly one monochrome pixel wide and one monochrome pixel high. Before an application can use a memory DC for drawing operations, it must select a bitmap of the correct width and height into the DC. To select a bitmap into a DC, use the CreateCompatibleBitmap function, specifying the height, width, and color organization required.

When a memory DC is created, all attributes are set to normal default values. The memory DC can be used as a normal DC. You can set the attributes; obtain the current settings of its attributes; and select pens, brushes, and regions.

The CreateCompatibleDC function can only be used with devices that support raster operations. An application can determine whether a device supports these operations by calling the GetDeviceCaps function.

When you no longer need the memory DC, call the DeleteDC function.

Windows 2000 and later: If hdc is NULL, the thread that calls CreateCompatibleDC owns the HDC that is created. When this thread is destroyed, the HDC is no longer valid. Thus, if you create the HDC andpass it to another thread, then exit the first thread, the second thread will not be able to use the HDC.

 

繪制三維文本網格模型

創(chuàng)建好文本的網格模型之后,就可以使用ID3DXMesh的接口函數DrawSubset()將其繪制出來,在繪制之前,需要注意設置合適的世界矩陣,這時雖然是繪制三維文本,但實質上就是繪制一個三維物體,所以為三維文本設置世界矩陣是必不可少的。示例代碼如下:

void setup_world_matrix()
{
D3DXMATRIX mat_translation;
D3DXMatrixTranslation(&mat_translation, -1.75f, 0.0f, 0.0f);
	D3DXMATRIX mat_world;
D3DXMatrixRotationY(&mat_world, timeGetTime()/1000.0f);
	mat_world = mat_translation * mat_world;
	g_device->SetTransform(D3DTS_WORLD, &mat_world);
}
void render()
{
g_device->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_X#050505, 1.0f, 0);
	g_device->BeginScene();
	setup_world_matrix();
g_text_mesh->DrawSubset(0);
	g_device->EndScene();
	g_device->Present(NULL, NULL, NULL, NULL);
}

使用D3DXCreateText()函數為文本創(chuàng)建網格模型時,網格模型的原點在左下方,所以需要對文本網格模型進行平移,使其基本上顯示在窗口的中央。

 

源程序:

#include <D3DX9.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;
ID3DXMesh
*                g_text_mesh;

void setup_world_matrix()
{
    D3DXMATRIX mat_translation;
    D3DXMatrixTranslation(
&mat_translation, -1.75f0.0f0.0f);

    D3DXMATRIX mat_world;
    D3DXMatrixRotationY(
&mat_world, timeGetTime()/1000.0f);

    mat_world 
= mat_translation * mat_world;

    g_device
->SetTransform(D3DTS_WORLD, &mat_world);
}

void setup_view_proj_matrices()
{
    D3DXVECTOR3 eye(
0.0f0.0f,-8.0f);
    D3DXVECTOR3  at(
0.0f0.0f0.0f);
    D3DXVECTOR3  up(
0.0f1.0f0.0f);

    D3DXMATRIX mat_view;
    D3DXMatrixLookAtLH(
&mat_view, &eye, &at, &up);
    g_device
->SetTransform(D3DTS_VIEW, &mat_view);

    D3DXMATRIX mat_proj;
    D3DXMatrixPerspectiveFovLH(
&mat_proj, D3DX_PI/41.0f1.0f100.0f);
    g_device
->SetTransform(D3DTS_PROJECTION, &mat_proj);
}

void setup_material_light()
{
    D3DMATERIAL9 material;
    ZeroMemory(
&material, sizeof(D3DMATERIAL9));

    material.Diffuse.r 
= material.Ambient.r = 1.0f;
    material.Diffuse.g 
= material.Ambient.g = 1.0f;
    material.Diffuse.b 
= material.Ambient.b = 1.0f;
    material.Diffuse.a 
= material.Ambient.a = 1.0f;

    g_device
->SetMaterial(&material);
    
    D3DLIGHT9 light;
    ZeroMemory(
&light, sizeof(D3DLIGHT9));

    light.Type       
= D3DLIGHT_DIRECTIONAL;
    light.Diffuse.r  
= 0.0f;
    light.Diffuse.g  
= 1.0f;
    light.Diffuse.b  
= 1.0f;
    light.Range      
= 1000.0f;

    D3DXVECTOR3 light_dir(
111);
    D3DXVec3Normalize((D3DXVECTOR3
*)&light.Direction, &light_dir);
    
    g_device
->SetLight(0&light);
    g_device
->LightEnable(0, TRUE);
    g_device
->SetRenderState(D3DRS_LIGHTING, TRUE);
    
    g_device
->SetRenderState(D3DRS_AMBIENT, 0xffFF50FF);
}

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;
    }

    HDC hdc 
= CreateCompatibleDC(NULL);
    
if(hdc == NULL)
        
return false;

    HFONT hfont 
= CreateFont(0000, FW_BOLD, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,
                             CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH 
| FF_DONTCARE, L"Arial");

    SelectObject(hdc, hfont);

    D3DXCreateText(g_device, hdc, L
"三維字體"0.001f0.4f&g_text_mesh, NULL, NULL);

    DeleteObject(hfont);
    DeleteDC(hdc);

    g_device
->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
    g_device
->SetRenderState(D3DRS_LIGHTING, TRUE);
        
    setup_view_proj_matrices();
    setup_material_light();

    
return true;
}

void cleanup()
{
    release_com(g_text_mesh);
    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();

    setup_world_matrix();
    g_text_mesh
->DrawSubset(0);

    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    
= L"GameApp";
    wc.hIconSm            
= NULL;

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

    HWND hwnd 
= CreateWindow(L"GameApp", L"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(L
"GameApp", wc.hInstance);    

    
return 0;
}

 

posted on 2008-05-11 20:48 lovedday 閱讀(1838) 評論(0)  編輯 收藏 引用


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


公告

導航

統(tǒng)計

常用鏈接

隨筆分類(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>
            午夜精品久久久久久久| 午夜一区二区三区在线观看| 麻豆精品在线视频| 亚洲韩日在线| 亚洲高清在线观看一区| 欧美成人a∨高清免费观看| 亚洲免费av电影| 99精品欧美一区二区三区综合在线| 欧美看片网站| 午夜视频一区二区| 久久久久久久综合日本| 91久久综合| 亚洲少妇自拍| 国产综合亚洲精品一区二| 国产日韩专区| 美女精品自拍一二三四| 美女诱惑黄网站一区| 一本久久a久久精品亚洲| 亚洲图片在线观看| 国产一区二区三区在线观看精品 | 免费一级欧美在线大片| 欧美韩日一区| 性高湖久久久久久久久| 久久精品在线免费观看| 日韩亚洲精品视频| 欧美一区二区三区四区在线| 国产精品爽爽爽| 先锋a资源在线看亚洲| 狠狠色狠狠色综合日日91app| 男同欧美伦乱| 国产精品v一区二区三区| 久久久久一本一区二区青青蜜月| 久久综合久久综合九色| 亚洲直播在线一区| 久久久一二三| 亚洲欧美激情视频| 美国成人直播| 香蕉久久夜色精品国产使用方法| 久久综合久色欧美综合狠狠 | 国产精品视频xxx| 欧美成人激情在线| 国产亚洲成年网址在线观看| 亚洲国产一区二区三区青草影视| 欧美一区二区三区四区在线 | 国产欧美一区二区三区在线看蜜臀| 麻豆视频一区二区| 国产精品乱码一区二三区小蝌蚪| 亚洲大黄网站| 狠狠色狠狠色综合日日91app| 一本色道久久精品| 99一区二区| 免费在线看一区| 久久综合国产精品台湾中文娱乐网| 欧美三区不卡| 日韩视频中文字幕| 亚洲精品乱码久久久久久蜜桃91 | 亚洲三级色网| 亚洲经典在线看| 久久精品国产99| 久久只精品国产| 激情自拍一区| 久久九九免费视频| 葵司免费一区二区三区四区五区| 国产日韩欧美一区二区| 亚洲一区二区三区视频播放| 亚洲一区在线观看免费观看电影高清| 欧美日韩国产精品自在自线| 欧美激情国产精品| 91久久综合| 欧美激情一区二区三区高清视频| 亚洲国产视频一区二区| 亚洲精品视频在线看| 欧美α欧美αv大片| 亚洲国产日韩欧美一区二区三区| 亚洲精品日韩久久| 欧美另类变人与禽xxxxx| 亚洲精品在线电影| 亚洲欧美美女| 国产嫩草一区二区三区在线观看| 午夜伦欧美伦电影理论片| 欧美在线你懂的| 国内精品久久久久国产盗摄免费观看完整版 | 日韩视频一区二区三区在线播放免费观看| 牛人盗摄一区二区三区视频| 亚洲精品网站在线播放gif| 一区二区三区精品在线| 国产精品一区毛片| 久久久欧美精品sm网站| 亚洲欧洲一区二区三区| 亚洲欧美日韩成人高清在线一区| 国产乱人伦精品一区二区 | 亚洲精品乱码久久久久久久久| 亚洲美女淫视频| 国产精品久久久久永久免费观看| 午夜亚洲视频| 亚洲福利专区| 午夜精品在线| 亚洲第一在线| 国产精品丝袜久久久久久app| 欧美自拍丝袜亚洲| 亚洲人体1000| 久久久人成影片一区二区三区观看 | 亚洲欧美日韩国产一区| 欧美承认网站| 午夜精品国产更新| 91久久精品日日躁夜夜躁欧美| 国产精品yjizz| 欧美99久久| 欧美在线视频播放| 日韩一区二区精品视频| 狂野欧美激情性xxxx| 亚洲免费在线观看| 亚洲精品中文字幕女同| 国产一区三区三区| 国产精品v片在线观看不卡| 久久久久久亚洲精品中文字幕| 99在线精品视频| 欧美成人免费全部| 久久国产综合精品| 亚洲影院在线| 日韩天堂av| 亚洲国产综合在线| 黄色在线一区| 国产亚洲欧洲一区高清在线观看| 欧美日韩一区二区三区四区五区| 麻豆成人在线观看| 久久精品日产第一区二区| 正在播放亚洲一区| 夜夜狂射影院欧美极品| 亚洲国内在线| 亚洲夫妻自拍| 欧美激情性爽国产精品17p| 久久欧美肥婆一二区| 欧美在线视频不卡| 欧美一级大片在线观看| 亚洲主播在线| 亚洲午夜一区二区三区| 一本色道综合亚洲| 99国产精品视频免费观看| 亚洲日本视频| 亚洲精品视频啊美女在线直播| **性色生活片久久毛片| 亚洲国产经典视频| 亚洲福利视频专区| 亚洲第一狼人社区| 亚洲福利小视频| 亚洲人成亚洲人成在线观看图片| 亚洲激情啪啪| 亚洲人成人一区二区三区| 最新精品在线| 99精品视频一区| 亚洲综合国产| 久久国产精品久久久久久| 久久久久国产精品一区二区| 久久久夜夜夜| 欧美成人午夜激情| 亚洲人成在线播放网站岛国| 亚洲精品一区二区三区在线观看| 亚洲精品国精品久久99热一| 日韩视频中文字幕| 午夜影院日韩| 久久网站免费| 欧美人与性动交cc0o| 国产精品jizz在线观看美国| 国产视频一区二区三区在线观看| 合欧美一区二区三区| 91久久精品国产91久久性色tv | 亚洲黄色影片| 99re亚洲国产精品| 亚洲欧美bt| 久久综合伊人77777| 亚洲欧洲另类| 亚洲一区二区3| 麻豆成人在线观看| 欧美午夜精品理论片a级按摩| 国产农村妇女毛片精品久久莱园子| 伊人久久婷婷色综合98网| 一本久道久久综合中文字幕 | 1024成人网色www| 99国产精品久久久久老师| 久久国产日韩欧美| 亚洲大胆人体视频| 在线一区亚洲| 免费亚洲电影在线| 国产精品五区| 亚洲每日在线| 久久色在线播放| 在线综合亚洲欧美在线视频| 久久久久久夜| 国产精品一区二区久激情瑜伽| 亚洲高清资源| 欧美一区二区视频在线观看2020| 亚洲国产高清在线观看视频| 亚洲欧美日韩在线观看a三区| 欧美激情乱人伦| 伊人久久成人| 久久久噜噜噜久噜久久 | 欧美激情一区二区三区 | 欧美福利视频在线| 亚洲一区欧美二区|