Jump to content
  • Advertisement
Sign in to follow this  

Fastest way to render text?

This topic is 3078 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I was thinking I could draw the text glyphs to the alpha of a texture and then FillRect() the desired color. The problem now that I think about it is that I have to use render-to-texture to get my font onto textures... I'll end up having a ton of render-target textures and I will have to render-to-texture allot as well.

Is there a better way?


Share this post

Link to post
Share on other sites
I have my own implementation, but I was trying to make it more versatile. (I have used d3dx however)

I'm talking about for a bitmap font type setup, what is the fastest way in your opinion?

Share this post

Link to post
Share on other sites
Oh, I see; so each letter is in its own bitmap file? FillRect() is a GDI thing, not a DirectX-based function, am I right?

I don't know where DirectX comes into this, but I have an idea for you if you're using Direct3D.

I'd put all my letters in one bitmap, evenly spaced apart (or not--depends on what you want to do). Then I'd let 0 = A, 1 = B, 2 = C. Then I'd make a strip of vertices that's just a bunch of connected squares, with double vertices at each overlap. Then I'd put a letter on each square with texture coordinates.

So, my bitmap file of the alphabet stores each letter as a 32x32 square let's say:
A B C D E F G H I ... etc.

I make a horizontal grid of vertices, with doubles on the overlapping edges of the individual squares I'm trying to form.

1 2/5 7/9 11

3 4/6 8/10 12

That's 3 square right there.

Now I want to write "CAT"; I know C = 2, A = 0, T = 19.

If I have 26 letters in my bitmap, I know that there is a texture coordinate of 1/26 between the letters (remember texture coordinates go from 0 to 1).

Now I start setting some texture coordinates.
C = 2.

So I set the following texture coordinates (U, V) for each vertex for the letter C:
1: (2 * 1/26, 0)
2: (2 * 1/26, 1)
3: (3 * 1/26, 0)
4: (3 * 1/26, 1)

A = 0. So for A:
5: (0 * 1/26, 0)
6: (0 * 1/26, 1)
7: (1/26, 0)
8: (1/26, 1)

T = 19.
9: (19 * 1/26, 0)
10: (19 * 1/26, 1)
11: (20 * 1/26, 0)
12: (20 * 1/26, 1)

And I'm done.

Does that work for you, or do you need something in GDI?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!