Jump to content
  • Advertisement
Sign in to follow this  
Antonym

DirectX Font Changing Size/Style

This topic is 3499 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

I am using direct3d and the and the ID3DXFont object and was wondering if there was a way to change the size of the font/style/properties in general displayed. Do I have to create an object per font size/type I want displayed? I am not familiar with the fonts and I am looking for one that would look good in a space/futuristic/battleship game. Anyone knows any which could fit this description? Also I am not really liking any of the fonts available, this is my first game though and I am somewhat new, should I consider creating my own font? How does one go about doing something like this? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Have you taken a look at the SDK's DirectText sample? It contains a whole lot of information for rendering 2D and 3D fonts with differnet types, colours, sizes etc, also the MSDN font interface documentation will tell you what functions you require to set and get certain values for or from the interface.

Share this post


Link to post
Share on other sites
When I used Direct3D ID3DXFont did lots of useless stuff and slowed the whole application down a good bit.
Its also more flexible to go with bitmap fonts.
For a sample you could check nehes bitmap font tutorial or this one
For fonts you could check pages like dafont and to generate bitmaps from that tools like bitmap font builder

If you still want to use ID3DXFont then you should read on the msdn or look at the sample code provided with the DirectX SDK.

Share this post


Link to post
Share on other sites
Quote:
Original post by Antonym
Do I have to create an object per font size/type I want displayed?
Yes.

Although as others have said, if you want a more custom looking font, bitmap fonts would probably be more flexible.

Share this post


Link to post
Share on other sites
Thanks a lot for the links! Though about that tutorial, that's opengl? Since I am using direct3d(And won't be using directx font) should I look for a similar tutorial with windows api or something of the like?

Share this post


Link to post
Share on other sites
You problably mean DirectX OR Direct3D API and not windows API. Well its the same for OpenGL and Direct3D.
Here is a short summary of what you have to do:

There are 256 ASCII symbols. Your texture is going to be a 16x16 matrix (16 symbols in each row, 16 rows)
So what you have to do is kinda simple.
'A' equals 0x41. Each Hex-Letter can display 16 different values - which is kinda good because you can simply parse it like this:
(0x41 & 0xF0) >> 8 = 0x4; So the letter we are looking for is in row 4 (Starting from 0)
(0x41 & 0xF) = 0x1; So the letter is in column 1 (Also starting from 0)



Pretty simple, eh?
So if your texture coordinate is from 0.0 to 1.0 all you have to do is this:

- Get row and column of your letter like I described above
- Multiply the row by 1.0/16.0 for the U texture-coordinate
- Multiply the column by 1.0/16.0 for the V texture-coordinate
- Render a quad and advance the X position for the next quad by checking the font-width file (which you can also generate using the bitmap font builder, its an array of 2 byte integers which hold the width in pixels for each symbol)
(Loop through your string until you reach a '\0' (Zero termination) in your string)

Share this post


Link to post
Share on other sites
What I meant with windows api was, since I am no longer going to use directx/3d to draw my font should I do it with the windows api?

That's not the same as using a texture to draw text(Which I thought was bad)?

Share this post


Link to post
Share on other sites
Quote:
Original post by Antonym
What I meant with windows api was, since I am no longer going to use directx/3d to draw my font should I do it with the windows api?


What _are_ you going to use then?
What they are describing as bitmap fonts, is using textured quads with directx.

Quote:

That's not the same as using a texture to draw text(Which I thought was bad)?


What's not? Why is it bad? I've never come across any flexible alternative.

The only two options I've ever seen is
1) use d3dxfont, which in the past, people have said stinks
2) create your own bitmap font, using textures quads (and render them with directx)



Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net 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!