Jump to content
  • Advertisement
Sign in to follow this  
Ataru

3D Text

This topic is 5397 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'm thinking of adding in some basic 3D text in my app as quickly as possible. My first idea was to use the ID3DXFont::DrawText and billboard the quads. This produces less than stellar results, as it seems that each letter is a quad, and the whole text does not allign with the viewer, rather just individual letters. I'd rather not have to generate my own font bitmap, and use the one generated by the font class. Anyone know a way of extracting a texture created by the font class, that I can simply stick onto my own billboards?

Share this post


Link to post
Share on other sites
Advertisement
Shameless bump. No easy way to do this using standard DX libs? I guess I'll have to write my own font to bitmap class. A little more work, but it does not look like there's much I can do about it.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Well, I don't know if it helps any, but this is the way I did my 2D text rendering.

1.) switch the projection to ortho

2.) paste the letters from a fixed width font into a static texture (with 2 lines in the grid for normal 2 for bold, 2 for italics)

3.) create a separate quad for each letter in the text, and apply the alpha channel of the texture to each quad with the appropriate texture coordinate offset.

Here is some sample code it will need to be sped up, and tested for leaks because I wrote it in about 10 minutes and haven't had time to test or comment it... but it does work:


#define FONT_ONE_PIXEL 0.00390625
#define CDXGO_FONT_WIDTH 8
#define CDXGO_FONT_HEIGHT 13

void GetFontTextureCoordinates( char inChar, float& x, float& y, float& x2, float& y2 )
{
char workingChar = inChar-32;

if (workingChar94) workingChar = 94;

if (workingCharDevice()->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
mDirectXContext->Device()->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_CURRENT);
mDirectXContext->Device()->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
// alpha = texture * diffuse (vertex or material)

mDirectXContext->Device()->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
mDirectXContext->Device()->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
mDirectXContext->Device()->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);

// Terminate texture stages

mDirectXContext->Device()->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
mDirectXContext->Device()->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);


mDirectXContext->Device()->SetFVF( DXW_FVF_COLOREDTEXTUREDVERTEX );
mFontTexture->Set();

//now, loop through all the characters in the text and paint them on the screen with the correct texture offset!
float fx,fy,fx2,fy2;
for (i=0;iUnSet();

mDirectXContext->Device()->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_DISABLE);
mDirectXContext->Device()->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_DISABLE);

mDirectXContext->Device()->SetFVF( DXW_FVF_VERTEX );
}

}

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
eww... what happened there, it cut chunks of my post out. Well, if you want the code or the actual texture, just email me privately. my addr is

s m c b r i d e @ j v b f i n a c i a l . c o m

Share this post


Link to post
Share on other sites
You can create 3d text pretty much in 3 steps with the D3DX library:

1. Create a font with CreateFont.
2. Create a mesh of the text by calling D3DXCreateText.
3. Render the text with ID3DXMesh::DrawSubset.

Share this post


Link to post
Share on other sites
Thanks. I knew about the mesh version. I was hoping not to have to go that route, and use a billboard. But since I am pressed for time rather than my ideal solution, I think this makes the most sense.

Thanks

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!