Sign in to follow this  
tnarol

[Direct3D] DrawText and rotation

Recommended Posts

Hi, I need to write some text vertically. I tried to use "SetTransform" with a rotation matrix then use the "DrawText", but it doesn't work. I guess "DrawText" probably doesn't support transformations. Which options do I have ? Thanks

Share this post


Link to post
Share on other sites
This sounds more like a win32 question than a Direct3D question.

DrawText does not support drawing with a non-0 orientation or escapement (says so right in MSDN) which is required for drawing vertical text. You have to use ExtTextOut.

Share this post


Link to post
Share on other sites
Quote:
Original post by tnarol
It is a Direct3D question. DrawText is part of the D3DDevice methods.
Actually, it's part of ID3DXFont, not D3DDevice.

I'm not sure if you can actually do this. You'll need to pass your own ID3DXSprite pointer to ID3DXFont::DrawText(). What do you mean SetTransform() "doesn't work"? What happens? I suspect ID3DXFont::DrawText() would draw the text horizontally, with each letter rotated 90 degrees, since all DrawText() does it use the sprite to draw the letters.

Your best bet would be to write your own derived ID3DXSprite class that just wraps the real one, and adjust the parameters passed to Draw(). I'm really not sure how easy that would be though, I suspect it might just be trial and error.

ID3DXFont isn't really designed for drawing text in fancy ways, it's just a simple helper class. If you want to do more effects, you should look at writing your own font class.

Share this post


Link to post
Share on other sites
I found a way to do it. Not very simple but OK.

I create a texture then I draw all my text somewhere in the texture at initialization then at render time I use a sprite to pick up some text in the texture and I apply a -Pi/2 rotation on the sprite and it does the job. It is much faster than DrawText but it means you have to know the text you want to render in advance.

Possibly I could copy every single character in the texture then pickup and draw the right characters at runtime. I don't know if it would be more efficient than DrawText... Is this what you mean by creating my own font ?

I'm thinking of having a "sprite server" class to perform the pickup in the texture. Is it better to have one single big texture with all sprites copied at different places of the texture or it is roughly as efficient to have one small texture per sprite ?

Share this post


Link to post
Share on other sites
On larger texture is definitely preferable, texture switches can be expensive. I've written my own font class before, it uses GDI to draw glyphs to a texture as needed, so it won't keep adding new letters to the texture if the text is static.
This is essentially what ID3DXFont does under the hood anyway, it just draws a bunch of glyphs to textures (In a horribly, horribly inneficient way), then uses ID3DXSprite to draw those glyphs. I made a Journal Entry about what exactly it does a while back. My new version (Some code Here) is a lot nicer.

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