Handling multiple text sizes
Moderator: Coders of Rage
- mv2112
- Chaos Rift Junior
- Posts: 240
- Joined: Sat Feb 20, 2010 4:15 am
- Current Project: Java Tower Defence Game
- Favorite Gaming Platforms: N64/Xbox 360/PC/GameCube
- Programming Language of Choice: C/++, Java
- Location: /usr/home/mv2112
- Contact:
Handling multiple text sizes
In my engine i want to have freedom with what text size i can render with, but SDL_TTF only lets you choose 1 text size and you cant re-size it without reloading the text which gets slow. Right now i just pre-load all text sizes from 2-42, incrementing by 2 each time, however this is also inefficient and slow, especially on the Wii. How could i handle multiples text sizes efficiently? I have tried resizing the SDL_Surfaces with SDL_gfx but the quality isn't good. Any ideas?
-
- Chaos Rift Regular
- Posts: 173
- Joined: Thu Feb 11, 2010 9:46 pm
Re: Handling multiple text sizes
Where's the sense in loading a bunch of sizes you might not use in a particular application? Create a Font Manager and only load the sizes you know your going to be using in the application your building with the engine.
Personally, I load the fonts I need at startup and they are given an integer ID or a string name that I hash. Then I can just render text using any of the fonts I loaded.
Personally, I load the fonts I need at startup and they are given an integer ID or a string name that I hash. Then I can just render text using any of the fonts I loaded.
- mv2112
- Chaos Rift Junior
- Posts: 240
- Joined: Sat Feb 20, 2010 4:15 am
- Current Project: Java Tower Defence Game
- Favorite Gaming Platforms: N64/Xbox 360/PC/GameCube
- Programming Language of Choice: C/++, Java
- Location: /usr/home/mv2112
- Contact:
Re: Handling multiple text sizes
I had thought about doing that, i was just wondering if there was a better way than just loading the fonts you need.
- Ginto8
- ES Beta Backer
- Posts: 1064
- Joined: Tue Jan 06, 2009 4:12 pm
- Programming Language of Choice: C/C++, Java
Re: Handling multiple text sizes
Well if you could set up a texture and the corresponding texture coords, you could easily do it with OpenGL. If you set up the texture to be in a larger size than the default, you could just scale it down to whatever size you want the text to be, and it wouldn't have anywhere near the loss of quality that creating a texture of smaller-sized characters and scaling it up.mv2112 wrote:I had thought about doing that, i was just wondering if there was a better way than just loading the fonts you need.
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
Re: Handling multiple text sizes
Here's what I suggest. Create a Font Manager, which will load and free all fonts for you.
Make a function so you can do something like this:
And this function should load the font in that size if it's not already loaded. You could also implement reference counting, so then every time the font is called, a +1 goes to the ref, and everytime something is done using it, a -1 to the ref count.
In this way, when the count hits 0, you actually free the resource.
So let's say there's a standard game font you use for conversation boxes or such... I'll say it's Times New Roman size 12 for sake of example. So since you'll use this font throughout the game, you'll want it to always be in mem so you don't have to wait, so in your game initialization you do:
and in your quit stuff:
This way the reference count is at least 1 while the game is running.
I'm not too sure of what you'd store it in, because you essentially have 2 values that can be unique (font and size). I think multimap would work well though. Just have the key as a string, so then you can access all the sizes of that font you have loaded...
Actually, though, I think you can do a map of maps (essentially a 2d map?) So you could do something like: Fonts[font][size] To get your specific font...
Well that's all the thoughts I have on the matter...
Make a function so you can do something like this:
Code: Select all
FontManager->GetFont("name.ttf", size);
In this way, when the count hits 0, you actually free the resource.
So let's say there's a standard game font you use for conversation boxes or such... I'll say it's Times New Roman size 12 for sake of example. So since you'll use this font throughout the game, you'll want it to always be in mem so you don't have to wait, so in your game initialization you do:
Code: Select all
FontManager->LoadFont("Times New Roman.ttf", 12);
Code: Select all
FontManager->ReleaseFont("Times New Roman.ttf", 12);
I'm not too sure of what you'd store it in, because you essentially have 2 values that can be unique (font and size). I think multimap would work well though. Just have the key as a string, so then you can access all the sizes of that font you have loaded...
Actually, though, I think you can do a map of maps (essentially a 2d map?) So you could do something like: Fonts[font][size] To get your specific font...
Well that's all the thoughts I have on the matter...
- mv2112
- Chaos Rift Junior
- Posts: 240
- Joined: Sat Feb 20, 2010 4:15 am
- Current Project: Java Tower Defence Game
- Favorite Gaming Platforms: N64/Xbox 360/PC/GameCube
- Programming Language of Choice: C/++, Java
- Location: /usr/home/mv2112
- Contact:
Re: Handling multiple text sizes
I tried what Ginto8 said, but with SDL_gfx and it utterly failed. I'm too much of a noob at openGL to attempt it for my engine. I will probably just load the fonts i need on start up. Right now i will keep it the way it is until i know what font sizes i want to use. Thanks for the replies, i will most likely start learning openGL soon