| View previous topic :: View next topic |
| Author |
Message |
viridite
Joined: 08 Nov 2007 Posts: 16
|
Posted: Mon Nov 12, 2007 1:31 am Post subject: ttf algorithem |
|
|
Hi, guys
recently i'm trying to use SDL's ttf support to make a reader. currently i can use it to display the chinese fonts. but i found a serious problem:
1. i use a cache to read the file first to store some fonts .
2. before every draw of the screen i will then read the char from the buffer and transfer to unicode and then cache the metrics for this screen
3. draw a screen of the fonts.
i found it too slow when switching to another screen because every time i need to cache the metrics and load data from the memory stick. it's too slow!!!
so then i tried to cache all the chinese fonts in memory at the starting time but failed because it will run out of the memory. so i just wonder whether there are some good solutions for this kind of problems??
Thanks! |
|
| Back to top |
|
 |
viridite
Joined: 08 Nov 2007 Posts: 16
|
Posted: Mon Nov 12, 2007 2:14 pm Post subject: |
|
|
why nobody answer this?
did anybody use sdl ttf for development? |
|
| Back to top |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Mon Nov 12, 2007 2:28 pm Post subject: |
|
|
Never used it.
You need to wait more than a few hours. Remember that most of the people who would answer your question are professional programmers who just frequent this board in their spare time. You could go a couple days before getting a post. |
|
| Back to top |
|
 |
viridite
Joined: 08 Nov 2007 Posts: 16
|
Posted: Mon Nov 12, 2007 3:08 pm Post subject: |
|
|
thanks!
so you never used ttf to display something? OK.... do you have some interesting things to introduce? haha.
anyway, nice to meet you,kind man! |
|
| Back to top |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Mon Nov 12, 2007 3:44 pm Post subject: |
|
|
| Nope, never used TTF, but I'm thinking about it. My current GUI code all uses the debug printing, and while it does the job, it's not the prettiest thing. So I'm thinking about switching the display part of the gui to TTF. But that doesn't help you right now. :) |
|
| Back to top |
|
 |
tacoSunday

Joined: 31 Aug 2007 Posts: 34
|
Posted: Mon Nov 12, 2007 10:46 pm Post subject: |
|
|
If you are looking for speed, I would think rendering the ttf once to a bitmap font and then indexing into it with uv coords would be the way to go.
Hmm, just realized you are trying to use Chinese fonts wich would make for a huge bitmap font. I suppose you could use some caching scheme for the rendered chars. I don't know much about chinese writing, but I would assume most writing uses a rather limited subset at any one time. |
|
| Back to top |
|
 |
viridite
Joined: 08 Nov 2007 Posts: 16
|
Posted: Mon Nov 12, 2007 11:16 pm Post subject: |
|
|
| tacoSunday wrote: | If you are looking for speed, I would think rendering the ttf once to a bitmap font and then indexing into it with uv coords would be the way to go.
Hmm, just realized you are trying to use Chinese fonts wich would make for a huge bitmap font. I suppose you could use some caching scheme for the rendered chars. I don't know much about chinese writing, but I would assume most writing uses a rather limited subset at any one time. |
haha, i've tried ... but memory is not enough.......... |
|
| Back to top |
|
 |
tacoSunday

Joined: 31 Aug 2007 Posts: 34
|
Posted: Tue Nov 13, 2007 7:10 pm Post subject: |
|
|
I realize that memory may not be enough. That is why I suggested caching recently used characters instead of the entire character set. This was based on the assumption that only a relatively small subset of them would be in use at any given time. You have a cache of a fixed size (which you tweak to fit in available memory) and when the cache is full and you come across a char that is not already cached render it and and shove it in the cache position of the least recently used char that is cached. I am willing to bet that this will provide acceptable performance .
Best of luck
P.S. I do believe I have set a record for the most uses of the word cache in a single run-on sentence! |
|
| Back to top |
|
 |
viridite
Joined: 08 Nov 2007 Posts: 16
|
Posted: Tue Nov 13, 2007 7:33 pm Post subject: |
|
|
Thanks.
but i think that is not realistic because every try of caching data will cost at least one to two seconds. so once we need to cache some data the user needs to wait two seconds or more , it's not good at least at the very first of the caching process.
but maybe i can try to cache several pages first and then if there are more characters in need i will cache again.....
but in fact i found a famous ereader can finish this without any problem. so i guess there shall be some tricks. |
|
| Back to top |
|
 |
tacoSunday

Joined: 31 Aug 2007 Posts: 34
|
Posted: Wed Nov 14, 2007 4:58 am Post subject: |
|
|
| Quote: | | but maybe i can try to cache several pages first and then if there are more characters in need i will cache again..... |
That there is the answer! Once the cache is filled it gets far better. You can do this ahead of time by studying the frequency of Chinese ideograms and prepopulating the cache with the most common chars. Then the only time you have to wait for loading is when you have a cache miss. If your cache is large enough this should be a relatively infrequent occurrence. For further speedups you could then look ahead and load needed chars in the background before the user even gets to that page.
Trust me, this subject is old hat in the CS field and well studied.
The link is just a google search for texture caching schemes. Your problem is no different than texture caching and pre-caching. You are simply caching a dynamically generated texture.
good luck |
|
| Back to top |
|
 |
viridite
Joined: 08 Nov 2007 Posts: 16
|
Posted: Wed Nov 14, 2007 12:01 pm Post subject: |
|
|
Thanks very much...
I tried yesterday and it did speed up... i will try to make it faster by imporving the algorithem. somehow it works fine.
currently i used a cache to load hundreds of charactors and once there appears one that isn't hit in the cache i will replace it with the least used one.
so this method do solved my problem. thanks, everybody. |
|
| Back to top |
|
 |
|