Advertisement Jump to content
Sign in to follow this  

Multiple lines with 3D text

This topic is 4894 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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,
			"Arial" );
hFontOld = (HFONT)SelectObject(hdc, hFont); 

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

Share this post

Link to post
Share on other sites
ID3DXFont::DrawText Method Documentation
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.

myFont->DrawText( NULL, "one\ntwo", -1, &rc, DT_WORDBREAK, someColor );

Share this post

Link to post
Share on other sites
Sorry, I didn't notice you were working with 3D text.
In that case I don't know how to help you.

Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!