Skip to main content
GameDev.net gamedev.net
🔒 Locked

Texture Fonts

Started by Games Apprentice Jul 18, 2009 at 5:42 AM 4 replies 800+ views
Original Post
Games Apprentice
Games Apprentice
Hi everyone, please help me out. I wanted to try like for instance I have a texture 'fonts.dds', how do i render those fonts representing the letters? I'm aware that I should create a class for alphabets. I just haven't figure out how I'd render them to the screen. Do I use an array of ID3DXTexture for each mapped letters? Any ideas? Examples or links would help a lot. Thanks Thanks!
Zahlman
Zahlman
Without getting into any platform specifics, the general approach is: put all the letters on one texture, and store instances of some rectangle class which represent the bounds on the texture of each letter. To render a character, you figure out where it needs to go, set up a quad, look up the rectangle for that character (that would be ((left, top), (left + width, top), (left + width, top + height), (left, top + height)) - possibly in a different order, depending on your API), and apply the corresponding UV coordinates to the vertices of the quad.

It's basically the same as using a spritesheet in a traditional 2D game, except that you need to calculate all four corner positions on the "spritesheet" (your texture) and associate them with positions in the 3D object space (instead of directly with screen positions).
Zakwayda
Zakwayda
@The OP: This seems to be a cross-post, more or less (even though the content of the posts isn't exactly the same). I don't know if the mods will care in this case, but just FYI, you generally shouldn't post the same question in multiple forums.
Games Apprentice
Games Apprentice
Quote:
Original post by Zahlman
Without getting into any platform specifics, the general approach is: put all the letters on one texture, and store instances of some rectangle class which represent the bounds on the texture of each letter. To render a character, you figure out where it needs to go, set up a quad, look up the rectangle for that character (that would be ((left, top), (left + width, top), (left + width, top + height), (left, top + height)) - possibly in a different order, depending on your API), and apply the corresponding UV coordinates to the vertices of the quad.

It's basically the same as using a spritesheet in a traditional 2D game, except that you need to calculate all four corner positions on the "spritesheet" (your texture) and associate them with positions in the 3D object space (instead of directly with screen positions).


Thank you! I'll try that.
Games Apprentice
Games Apprentice
Quote:
Original post by Zahlman
Without getting into any platform specifics, the general approach is: put all the letters on one texture, and store instances of some rectangle class which represent the bounds on the texture of each letter. To render a character, you figure out where it needs to go, set up a quad, look up the rectangle for that character (that would be ((left, top), (left + width, top), (left + width, top + height), (left, top + height)) - possibly in a different order, depending on your API), and apply the corresponding UV coordinates to the vertices of the quad.

It's basically the same as using a spritesheet in a traditional 2D game, except that you need to calculate all four corner positions on the "spritesheet" (your texture) and associate them with positions in the 3D object space (instead of directly with screen positions).


Thank you! I'll try that.
Games Apprentice
Games Apprentice
Quote:
Original post by jyk
@The OP: This seems to be a cross-post, more or less (even though the content of the posts isn't exactly the same). I don't know if the mods will care in this case, but just FYI, you generally shouldn't post the same question in multiple forums.


I'll have that in mind, I'm sorry.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.