forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

ttf algorithem

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
viridite



Joined: 08 Nov 2007
Posts: 16

PostPosted: Mon Nov 12, 2007 1:31 am    Post subject: ttf algorithem Reply with quote

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
View user's profile Send private message
viridite



Joined: 08 Nov 2007
Posts: 16

PostPosted: Mon Nov 12, 2007 2:14 pm    Post subject: Reply with quote

why nobody answer this?
did anybody use sdl ttf for development?
Back to top
View user's profile Send private message
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Mon Nov 12, 2007 2:28 pm    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
viridite



Joined: 08 Nov 2007
Posts: 16

PostPosted: Mon Nov 12, 2007 3:08 pm    Post subject: Reply with quote

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
View user's profile Send private message
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Mon Nov 12, 2007 3:44 pm    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
tacoSunday



Joined: 31 Aug 2007
Posts: 34

PostPosted: Mon Nov 12, 2007 10:46 pm    Post subject: Reply with quote

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
View user's profile Send private message
viridite



Joined: 08 Nov 2007
Posts: 16

PostPosted: Mon Nov 12, 2007 11:16 pm    Post subject: Reply with quote

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
View user's profile Send private message
tacoSunday



Joined: 31 Aug 2007
Posts: 34

PostPosted: Tue Nov 13, 2007 7:10 pm    Post subject: Reply with quote

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
View user's profile Send private message
viridite



Joined: 08 Nov 2007
Posts: 16

PostPosted: Tue Nov 13, 2007 7:33 pm    Post subject: Reply with quote

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
View user's profile Send private message
tacoSunday



Joined: 31 Aug 2007
Posts: 34

PostPosted: Wed Nov 14, 2007 4:58 am    Post subject: Reply with quote

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
View user's profile Send private message
viridite



Joined: 08 Nov 2007
Posts: 16

PostPosted: Wed Nov 14, 2007 12:01 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group