Sign in to follow this  
striker87

How to display text

Recommended Posts

Hi I was wondering if anyone knows where I can find a tutorial that shows how to display text with Directx 10 as planning on making a simple spelling game for my son and updating it through the year with his spelling word lists from school. Thought this would be a fun way to get started with Directx as I'll be learning the fundamentals while making something to help my son with spelling words. Any help will be greatly appreciated. :)

Share this post


Link to post
Share on other sites
[quote name='striker87' timestamp='1318109188' post='4870594']
Hi I was wondering if anyone knows where I can find a tutorial that shows how to display text with Directx 10 as planning on making a simple spelling game for my son and updating it through the year with his spelling word lists from school. Thought this would be a fun way to get started with Directx as I'll be learning the fundamentals while making something to help my son with spelling words. Any help will be greatly appreciated. :)
[/quote]

Hey striker87,

There are many different ways to render text in Direct3D10, but the easiest route to take for a beginner is to make use of the [url="http://msdn.microsoft.com/en-us/library/windows/desktop/bb173886(v=vs.85).aspx"]ID3DX10Font[/url] interface. Essentially, you create a font with the [url="http://msdn.microsoft.com/en-us/library/windows/desktop/bb172664(v=vs.85).aspx"]D3DX10CreateFont[/url] function, then you can use the [url="http://msdn.microsoft.com/en-us/library/windows/desktop/bb173887(v=vs.85).aspx"]DrawText[/url] function to draw a specific string of text. If you need an example in code, I (or someone else) can make another post with an explicit example

Share this post


Link to post
Share on other sites
[quote name='Geiger' timestamp='1318111993' post='4870613']
[quote name='striker87' timestamp='1318109188' post='4870594']
Hi I was wondering if anyone knows where I can find a tutorial that shows how to display text with Directx 10 as planning on making a simple spelling game for my son and updating it through the year with his spelling word lists from school. Thought this would be a fun way to get started with Directx as I'll be learning the fundamentals while making something to help my son with spelling words. Any help will be greatly appreciated. :)
[/quote]

Hey striker87,

There are many different ways to render text in Direct3D10, but the easiest route to take for a beginner is to make use of the [url="http://msdn.microsoft.com/en-us/library/windows/desktop/bb173886(v=vs.85).aspx"]ID3DX10Font[/url] interface. Essentially, you create a font with the [url="http://msdn.microsoft.com/en-us/library/windows/desktop/bb172664(v=vs.85).aspx"]D3DX10CreateFont[/url] function, then you can use the [url="http://msdn.microsoft.com/en-us/library/windows/desktop/bb173887(v=vs.85).aspx"]DrawText[/url] function to draw a specific string of text. If you need an example in code, I (or someone else) can make another post with an explicit example


[/quote]

Thanks Geiger for pointing me in the right direction and if you or anyone else can make an example that would be great. Again thanks for the help.

Share this post


Link to post
Share on other sites
So the steps that need to be taken are:
1. Initialize an instance of ID3DX10Font. This interface stores all of the properties of a particular font in your application
[font="Consolas, Courier, monospace"]
[/font]
ID3DX10Font* mFont;
D3DX10CreateFont( md3dDevice, // ID3D10Device
24, // Height of the font
0, // Width of the font
0, // Weight (or Boldness) of the font
0, // Mip-levels to generate of the font
false, // Italic?
DEFUALT_CHARSET, // Character set of the font
OUT_DEFAULT_PRECIS, // Default Precision[/font]
DEFAULT_QUALITY, // Default Quality
DEFAULT_PITCH | FF_DONTCARE, // Default Pitch and Family
L"Times New Roman", // Name of the font to use
&mFont // Pointer to the ID3DX10Font interface to initialize

) );

[font="monospace"][size="2"]2. When you want to draw a particular string to the render target, use the font's [/size][/font][font="monospace"][size="2"]DrawText method:[/size][/font]

[font="monospace"][size="2"]RECT rectangle = { 0, 0, width, height };[/size][/font]

[font="monospace"][size="2"]mFont->DrawText( NULL, // "[/size][/font][color="#2A2A2A"]Direct3D will render the string with its own sprite object." -- MSDN[/color]
[color="#2A2A2A"] L"Draw this string", // "String to draw to the render target[/color]
[color="#2A2A2A"] -1, // Specifies the number of characters in the string (-1 counts them for us)[/color]
[color="#2A2A2A"] &rectangle, // Pointer to the rectangle we want to draw out text in[/color]
[color="#2A2A2A"] DT_NOCLIP | DT_VCENTER | DT_CENTER, // Draws the text in the center of the rectangle (horz & vert) and can exceed the rectangles boundaries[/color]
[color="#2A2A2A"] D3DXCOLOR( 1.0f, 1.0f, 1.0f, 1.0f ) ); // White color[/color]

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