Multiple lines with 3D text

Started by
3 comments, last by deffer 18 years, 7 months ago
Hi. Normally, I prefer the hard, *doItYourself*, way, but the more I "need something for tomorrow", the more I resolve to external libraries, so here I am.[grin] I wanted to render a 3D text. So I looked into DX SDK samples, and found one appropriate. It creates a ID3DXMesh interface, with drawable mesh with given text and font.

// This mesh would be our goal.
ID3DXMesh *pMeshNew = NULL;

// This is just for creating font.
HDC hdc = CreateCompatibleDC( NULL );
HFONT hFont;
HFONT hFontOld;
hFont = CreateFont( 0, 0, 0, 0, bBold ? FW_BOLD : FW_NORMAL, bItalic, FALSE, FALSE,
			DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH|FF_DONTCARE,
			"Arial" );
hFontOld = (HFONT)SelectObject(hdc, hFont); 

// CREATE 3D TEXT!
hr = D3DXCreateText( g_pDeviceD3D, hdc, szText, 0.001f, fDepth, &pMeshNew, NULL, NULL);

// And say goodbye to the font.
SelectObject(hdc, hFontOld);
DeleteObject( hFont );
DeleteDC( hdc );

Cool. Only that it apparently doesn't work with multi line text. It prints *squares* instead of '\n' or "\r\n". What can I do? ~def
Advertisement
Quote:ID3DXFont::DrawText Method Documentation
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.


Try passing the DT_WORDBREAK flag along with the other format flags in the ID3DXFont::DrawText function calls.

i.e.
myFont->DrawText( NULL, "one\ntwo", -1, &rc, DT_WORDBREAK, someColor );
But DrawText draws 2D text...
Sorry, I didn't notice you were working with 3D text.
In that case I don't know how to help you.
Well, since I was out of any smart ideas, and I needed it for today, I built a mesh for each line, and kept them in a vector, then rendered all of them in a row, with proper vertical offset.

A bit wasteful, but gets the job done.
~def

This topic is closed to new replies.

Advertisement