Archived

This topic is now archived and is closed to further replies.

alphatrak

Rendering text using d3d textures

Recommended Posts

alphatrak    163
Here''s what I want to do. I want to have a flexible way to display text using textures in directX 9. I want to use bitmaps (not neccessarily using .bmp format, but you know what I mean). I can think of a few ways to do this, but I''m not 100% aware of the disadvantages of each. Any input would be great, or if you have a different solution, please let me know: 1) I could render the image containing the bitmapped font to a surface, then create a texture for each character of the font by using UpdateSurface(). When rendering, I''d have to call SetTexture() for each letter. I''m not sure if this is a huge performance drop or not. I can''t imagine it would be too bad, since a lot of 3D games use several textures within a scene. 2) I could render the image containing the bitmapped font to a surface, then create a single texture for the entire font image. When rendering, I''d use UpdateSurface() to copy the rect of the character from the texture''s surface onto the surface of a texture that I''d actually be rendering. This way, I''d only be calling SetTexture() once, however, UpdateSurface() can only use a source surface that is in system memory, so I''d imagine this is not the best way. 3) I could render the image containing the bitmapped font to a surface, then create a single texture for the entire font image. I would have (U, V) texture coordinates already set up that allow me to apply each character''s portion of the texture to a primitive. I don''t think this would be very easy however Thanks, -Gordon

Share this post


Link to post
Share on other sites
alphatrak    163
ok.. now that I think about it, calculating (U, V) coords should be very simple. It should be nothing more than just:

(U, V) = (currentPixelX / bmpWidth, currentPixelY / bmpHeight)

So I''m thinking choice 3 is the best...?

Share this post


Link to post
Share on other sites
Yes 3 is best.

Remember to offset your UVs by half a texel so you''re sampling from the center of the texel rather than the edge (for instance using 1/width is directly between pixel 0 and 1, and bilinear blending will create a 50% mixed pixel as the result.)

UV coord = (x+0.5)/width, (y+0.5)/height

Also you may want to use RHW coordinates rather than trying to billboard the text. In RHW coordinates, X,Y are in screen pixels, Z should be between 0 and 1, the value doesn''t matter if you disable Z while drawing your text. W should be 1.0f.

Share this post


Link to post
Share on other sites