notJustCode.it
 
\\ Home : Articoli
Font
Di robydx (del 13/03/2007 @ 23:25:06, in English, linkato 2512 volte)

Let's start to do something of nice, and that will work. I know you would start now with 3D but before we have to start form 2D and we, now, will talk about fonts: how to write on the screen.

In DirectX10 (like in 9) the 2D graphics does not exists. Text and sprites (i'll talk about it nextly), are function written by Microsoft that moves some polygons with Z component = 0, in which it's interted images or text.

The using it's simple. Let's start with objects declaration:

ID3DX10Font* font;

HRESULT hr=D3DX10CreateFontA(device, 24, 0, FW_NORMAL, 1, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH|FF_DONTCARE, "Arial", & font);

First parameter it's device, the second the height (not the classic that you can see in Word, but in logic units), and width (if you set this parameter to 0, it will choose the right one).

There is weight and the text's depth,

FW_BLACK

FW_BOLD

FW_EXTRABOLD

FW_EXTRALIGHT

FW_HEAVY

There are other also, just take a look in WinAPI documentation.

There are the miplevels number (for now use 1, but i'll write entire articles about this concept) and a boolean value that specifies if use or not the cursive text.

There is charset, the precision type and quality (in this example, Antialiased option will draw the text more clear) and the impostation for pitch and family font (all this parameters are part of WinAPI library, nothing about DirectX.) At last, the address of interface that will contain the created font. If HRESULT will be = to S_OK then all it's gone ok.

Now we can use text to write:

font->DrawText(NULL,text,-1,&rectangle,DT_LEFT,D3DXCOLOR(1,1,1,1));

First parameter it's Sprite that i'll explain it in next tutorial. Using NULL D3D10 will use a normal rendering, but with a sprite we will be able to rotate and deform text, as a 3D object. The text parameter it's a string (const char* or LPCSTR that is a typedef). This will be the text drawed. The next parameter it's the width of text to print (-1 means all text). Rectangle it's a pointer to RECT structure and rapresent the zone in which will be inserted the text. The next parameter it's very important, and specifies how to draw text. Here are some (you can use more of this using the |operator)

DT_BOTTOM : used with DT_SINGLELINE, dress text in bottom

DT_CALCRECT : it will not write nothing but will compute the rect in which you will draw.

DT_CENTER : it will center text orizzontaly

DT_EXPANDTABS : expandes tabs

DT_LEFT : dress to left

DT_NOCLIP : Text won't be cutted. Performances will be increased.

DT_RIGHT : dress to right

DT_RTLREADING : show text in inverse side for nations (like Iraq :D) that use a inverse direction

DT_SINGLELINE : force text in a single line

DT_TOP : dress in up

DT_VCENTER : it will center text vertically (valid only in a single line)

DT_WORDBREAK :it will start a new line when text will go over rect.

A least the color. D3DXCOLOR will give you the color using red, green blu and alpha value. If you will use a lower value text will be semiInvisible. With 0 value it will be completely invisible.

Some other things on font: you can gain from font a DESC structure.

D3DX10_FONT_DESC desc;

font->GetDesc(&desc);

desc will contain all informations about text.

Optimizing text

When you render text, device generates images about it, but you can help DirectX by preload images, with this code.

font->PreloadCharacters(begin,end);

This istruction will mantain in memory the character and optimizing performance.

font->PreloadText("TEXT",-1);

This will preload a text. If you will write each time the same text, performance will be increased.

All istruction can be used with ASCII or UNICODE. For this, all function are in 2 versions: A and W.

Choose the right.

A special thanks goes to Vincent who translate this lesson.

Code

Articolo Articolo  Storico Storico Stampa Stampa
I commenti sono disabilitati.
"Un computer ti fa fare più errori e più velocemente di qualunque altra invenzione dell'uomo – con l'eccezione forse delle armi da fuoco e della tequila."

Mitch Ratcliffe


Cerca per parola chiave
 

Titolo
Articoli (4)
C++ (4)
Direct3D10 (30)
Direct3D11 (20)
DirectX9 (82)
DotNet (10)
English (9)
FanGames (22)
ManagedDX11 (2)
Materiale Utile (4)
News (39)
Shader Library (12)
SharpDX (1)
Software (25)
Tecnologia (19)
Varie (9)

Gli interventi più cliccati

Ultimi commenti:
If you wish to retai...
23/05/2013 @ 13:07:45
Di chanel outlet
You deficit of self-...
23/05/2013 @ 13:07:13
Di cartier watches uk
Reinforce your own l...
23/05/2013 @ 13:06:37
Di replica watches
Whenever you"re shiv...
23/05/2013 @ 13:06:11
Di swiss replica watches
It's likely you have...
23/05/2013 @ 13:05:02
Di chanel handbags
Cheap automobile ins...
23/05/2013 @ 13:04:28
Di replica watches

Titolo
Con quale tecnologia state realizzando o avete intenzione di realizzare i vostri progetti?

 DirectX11
 DirectX10
 DirectX9
 XNA
 DirectX8 o Precedenti
 OpenGL
 Motori grafici già pronti
 Altro

Titolo
Umorismo (17)

Le fotografie più cliccate



Ci sono 95 persone collegate
Sono state visualizzate  pagine

18/04/2024 @ 05:36:17
script eseguito in 48 ms