Sign in to follow this  
VanillaSnake21

Custom text engine, best approach?

Recommended Posts

Hi, I'm currently designing a custom text engine in c++ using direct x. My goal is for it to be usable in a game situation as well as normal "tool" text. What that implies is that it has to be able to fit into a 3D envirnoment well as well as be able to handle a large text file and edit it if its implemented in a tool. I decided that I want to make each letter into a polygon. I would have a large texture that would contain all my letters, and each polygon would be given an offset (x,y coords) so that the texture would be applied to it with the correct letter. My question is how do I do that. I am not that familiar with DX so the only way I know how to apply a texture is through SetTexture() method on the device. Can anybody help?

Share this post


Link to post
Share on other sites
Quote:
Original post by VanillaSnake21
Hi, I'm currently designing a custom text engine in c++ using direct x. My goal is for it to be usable in a game situation as well as normal "tool" text. What that implies is that it has to be able to fit into a 3D envirnoment well as well as be able to handle a large text file and edit it if its implemented in a tool. I decided that I want to make each letter into a polygon. I would have a large texture that would contain all my letters, and each polygon would be given an offset (x,y coords) so that the texture would be applied to it with the correct letter. My question is how do I do that. I am not that familiar with DX so the only way I know how to apply a texture is through SetTexture() method on the device. Can anybody help?
This can be done by manipulating the texture coordinates of the quads.

As a simple example, consider a texture with four characters on it, e.g.:
-----
|a b|
|c d|
-----
If the texture coordinate (0, 0) refers to the upper-left corner of the texture, then the texture coordinates for the character 'a' would be (clockwise from the bottom left):
( 0, .5)
( 0, 0)
(.5, 0)
(.5, .5)
For a real font with many characters, you would want to generate the texture coordinates programmatically. If the font is a monospace font, this is easy to do. Otherwise, you can use a tool like the AngelCode bitmap font generator to generate a file from which you can build the font.

Anyway, that would be the 'low-level' way to do it. I do it this way because I'm targeting multiple APIs (OpenGL and Direct3D), but I imagine that the DirectX library offers font tools that would take care of these details for you. (I don't how up-to-date it is, but here is some info that might be useful.)

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