ID3DXFont generated textures - how do I access them?

Started by
3 comments, last by Evil Steve 14 years, 10 months ago
I am using the ID3DXFont/sprite utility in DX9 to render text to the screen. I would like to use a pixel shader to enhance the text when rendering it. Primarily I'm trying to improve the smoothing/anti-aliasing on the text. Does anyone know how to access the texture that ID3DXFont generates for the font so I can sample from it? I tried getting it using the DC of the font, but that just seems to be a compatible DC not the actual DC of the surface of the texture. I've searched the forums and google and found one thread on here where someone said they used a pixel shader, but I'm not sure how they used the texture from ID3DXFont. The thread is here (and is locked or I would've posted there): http://www.gamedev.net/community/forums/topic.asp?topic_id=529421 Any help would be appreciated. Thanks.
Advertisement
Its not possible to get the textures generated by the ID3DXFont, after all it does not generate a whole TEXT texture, but gliphs with symbols that are local to the object (generated with GDI, and you don't know how many of them) and does lots of draws to create the whole text on screen with different texture coordinates.
You have 3 choices :

1) Use different render target, render the texture to that render target and reuse it to do the second pass on the pixel shader to smooth it.
2) Recreate the ID3DXFont so you can use whole text textures (in this case try to take a look at my blog for some ideas as i've already done it and it work quite well)
3) Mess out with the DC and GDI. (not good imho)
The only way you could do it is by passing a proxy IDirect3DDevice9 to D3DXCreateFont, and intercepting the calls to CreateTexture() to create your own proxy textures, and to then handle the locking and unlocking of the textures to grab the pixel information.

Although that's a pretty horrible way to do things - you'd be best off writing your own font renderer. ID3DXFont is just a helper class, it's not supposed to be any sort of ultimate solution.
It sure would be nice if ID3DXFont could just antialias text properly :P

I'm interested in a rewritten font renderer, has anyone else already recreated a DirectX 9 font renderer and made it public?
Construct (Free open-source game creator)
Quote:Original post by AshleysBrain
I'm interested in a rewritten font renderer, has anyone else already recreated a DirectX 9 font renderer and made it public?
I've written one, but it's pretty mixed in with some of my engine stuff (In particular my texture atlas and sprite code), and there's a few minor bugs.

If you want it anyway; PFont.h and PFont.cpp

This topic is closed to new replies.

Advertisement