Sign in to follow this  
Madalina

Direct3D 9, 3D text

Recommended Posts

Hello. I am trying to create 3D text using Direct3D 9. I have a problem, though. I can't change the font size. I have found the following piece of code in a tutorial and I don't understand how the font size is established since for the font hight the value is 0: HFONT hFont = CreateFont( 0, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, “Arial” ); HDC hdc = CreateCompatibleDC( NULL ); // Save the old font HFONT hFontOld = (HFONT)SelectObject(hdc, hFont); // Create the text mesh if ( FAILED( D3DXCreateText( pDevice, hdc, “C-Unit”, 0.01f, 0.4f, &m_pTextMesh, NULL, NULL ) ) ) { SHOWERROR( “D3DXCreateText() – Failed.”, __FILE__, __LINE__ ); } // Restore the old font and clean up SelectObject( hdc, hFontOld ); DeleteObject( hFont ); DeleteDC( hdc ); Could somebody explain to me why we have a font size when the height is 0? I hope that by understanding this I will be able to figure out why my font size doesn't change. Thank you in advance.

Share this post


Link to post
Share on other sites
Did you read the documentation?
Quote:

Parameters
nHeight [in]
The height, in logical units, of the font's character cell or character. The character height value (also known as the em height) is the character cell height value minus the internal-leading value. The font mapper interprets the value specified in nHeight in the following manner.

[snip]

0: The font mapper uses a default height value when it searches for a match.

[snip]

nWidth [in]
The average width, in logical units, of characters in the requested font. If this value is zero, the font mapper chooses a closest match value. The closest match value is determined by comparing the absolute values of the difference between the current device's aspect ratio and the digitized aspect ratio of available fonts.

Share this post


Link to post
Share on other sites
I read but not on MSDN. my stupid mistake. But now it is more a mystery to me why my font size doesn't change. No matter what Value I give for the height, the font remains the same. Therefore, it's still taking the default value.

Share this post


Link to post
Share on other sites
What if you put in a really large value? Like 100000?

Also, are you using the correct formula for font size from the MSDN:
nHeight = -MulDiv(PointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72);
(If you want to use a particular point size that is)

Share this post


Link to post
Share on other sites
I have tried with both very large number and the formula but nothing seems to work. It's really incredible. I have run out of ideas of what else to try. I was thinking about scaling the mesh objects but it's not a solution i found because i want to give as property the changing of font size.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this