Need fast font library
Need fast font library
Hi,
I'm working on a text editor, I've tried to use intraFont to blit text, but it's very slow, so I need a fastest font library?
What library can I use?
Better if with ttf support!
Thanks!
I'm working on a text editor, I've tried to use intraFont to blit text, but it's very slow, so I need a fastest font library?
What library can I use?
Better if with ttf support!
Thanks!
Get Xplora!
There's four ways of doing text: TTF (standard lib), PGFonts (custom font thingy used in the olden days), intraFont, and do-it-yourself. I haven't seen a case where intraFont was slow before. Might be something about how you're trying to use it rather than the lib itself. In general, if you think intraFont is too slow, you're going to have to do it yourself by hand for any better speed.
What I can do to speed up the blitting function of intraFont?
The text editor without text writted works at 100 fps, if I've a half of page with text it slows down to 10fps!
So, intraFont is slow to blit text!
I've already tried to speed it up doing what Benhur has sayd ( INTRAFONT_CACHE_ALL ) but it was still too much slow!
Is the ttf library more efficent?
Sorry for my english...
ne0h
The text editor without text writted works at 100 fps, if I've a half of page with text it slows down to 10fps!
So, intraFont is slow to blit text!
I've already tried to speed it up doing what Benhur has sayd ( INTRAFONT_CACHE_ALL ) but it was still too much slow!
Is the ttf library more efficent?
Sorry for my english...
ne0h
Get Xplora!
-
- Posts: 409
- Joined: Tue Oct 09, 2007 4:22 am
-
- Posts: 376
- Joined: Wed May 10, 2006 11:31 pm
You could look at pgeFont, which uses TrueType fonts and is fast http://www.psp-programming.com/forums/i ... 458.0.html
intraFont is base on the code of pgeFont.
I'm unsure why you're getting such a slowdown with intraFont, unless you're doing something fundamentally wrong.
intraFont is base on the code of pgeFont.
I'm unsure why you're getting such a slowdown with intraFont, unless you're doing something fundamentally wrong.
A texture mapped font library should be enough.
Just cull out unwanted data from the screen , and render only
what's inside screen bounds.
If you want even more speed , just create a multi-layered tile array ,
& render only what's inside screen.
This is extremely fast method , since you're not looping through each tile/layer ,
but only to those that you're actually need.
Here's how to render only needed elements:
Just cull out unwanted data from the screen , and render only
what's inside screen bounds.
If you want even more speed , just create a multi-layered tile array ,
& render only what's inside screen.
This is extremely fast method , since you're not looping through each tile/layer ,
but only to those that you're actually need.
Here's how to render only needed elements:
Code: Select all
//where "view" = some "camera" vector
unsigned int head_x = abs(app->view.x / font->glyph->w);
unsigned int head_y = abs(app->view.y / font->glyph->h);
unsigned int max_elems_x = ( app->window.w / font->glyph->w );
unsigned int max_elems_y = ( app->window.h / font->glyph->h );
unsigned int end_x = ((head_x+1) + max_elems_x)%tilelayer[active_layer]->w;
unsigned int end_y = ((head_y+1) + max_elems_y)%tilelayer[active_layer]->h;
//looping through active tiles
for ( register unsigned int y = head_y; y< end_y; y ++; )
{
for ( register unsigned int x = head_x; x< end_x; x ++; )
{
TTEntry* e = &tileLayer[active_layer]->map[y][x];
handle(e);
//lala
}
}
Ok, this is a a part of the main loop:
If I try to comment out "TextEditorBlitText();" I've something like 100fps, otherwise 10fps...
The same if I comment out "real_x = intraFontPrintf(real_x, real_y, "%c", c);"
This is the code of TextEditorBlitText:
This blit on char at time for getting the right cursor position.
Anyway I've tried to blit the entire line at time, but it's still slow.
If the text blitted is 2 lines I've 60 fps and no-one problem,
if I've all the page filled by text it slow down to 5 - 6 fps!!
Anyway thanks!
Insert_witty_name, I'll try pgeFont,
thanks!
EDIT:
Insert_witty_name, have you a link for download it?
The one posted doesn't work!
Code: Select all
while(1)
{
sceCtrlReadBufferPositive(&pad, 1);
ne0h_CtrlReadLatch(&latch);
WindowsMgr.Window(0, 0, 480, 272, "%s %s", language->globals.xplora , language->text_editor.text_editor);
TextEditorBlitText();
TextEditorBlitCursorIfNeeded();
intraFontPrintf(20, 20, "%d", cycle++);
if(danzeff) danzeff_render();
XgeScreenReplaceRefresh();
[... Othres checks for buttons ...]
}
The same if I comment out "real_x = intraFontPrintf(real_x, real_y, "%c", c);"
This is the code of TextEditorBlitText:
Code: Select all
void TextEditorBlitTextr()
{
int line_from = Text->first_visible_line;
int line_to = line_from + INTRAFONT_SCREEN_HEIGHT_LINES;
if(line_to > Text->lines) line_to = Text->num_lines;
int real_y_min = 30;
int real_x_min = 0;
int y = 0;
int real_y = real_y_min;
int line = line_from;
for(; line < line_to; line++)
{
TextLine* line1 = Text->lines[line];
if(line1 && line1->text)
{
int col_to = line1->col_max;
int x = 0;
int real_x = real_x_min;
int col = col_from;
for(; col_id < col_to; col_id++)
{
u8 c = a_line->text[col_id];
real_x = intraFontPrintf(real_x, real_y, "%c", c);
if(line_id == Text->curr_line)
{
cursor_pos[line_id][col_id] = real_x;
}
x++;
if(real_x > 470)
break;
}
}
y++;
real_y += psp_font_height;
if(y > INTRAFONT_SCREEN_HEIGHT_LINES)
break;
}
}
Anyway I've tried to blit the entire line at time, but it's still slow.
If the text blitted is 2 lines I've 60 fps and no-one problem,
if I've all the page filled by text it slow down to 5 - 6 fps!!
Anyway thanks!
Insert_witty_name, I'll try pgeFont,
thanks!
EDIT:
Insert_witty_name, have you a link for download it?
The one posted doesn't work!
Get Xplora!
First of all , you're on the wrong track of implementing an
editor.
You shoud go a bit low level , and handle the "code" buffer
where the text is stored , but oh , well...
Here's how to optimize a bit the code(assuming you're culling out
unwanted text to be rendered) (, but i will have to repeat myself : you're on the wrong track) :
editor.
You shoud go a bit low level , and handle the "code" buffer
where the text is stored , but oh , well...
Here's how to optimize a bit the code(assuming you're culling out
unwanted text to be rendered) (, but i will have to repeat myself : you're on the wrong track) :
Code: Select all
void TextEditorBlitTextr()
{
unsigned int line_from = Text->first_visible_line ,
//if this constant is what it sounds like , then
//you have to subtract it with current line index
line_to = (INTRAFONT_SCREEN_HEIGHT_LINES - line_from)%Text->num_lines,
y = 30 x = 0 , line = line_from;
for(; line < line_to; line++)
{
TextLine* line = Text->lines[line];
//assuming line structure has text structure which hold the text
intraFontPrintf(x, y, "%s", (char*)line->text);
y += psp_font_height + 1;
if(line_id == Text->curr_line)
{
cursor->x = (xscroll*character_width) % (Text->lines[line]->char_count *character_width);
curror->y = (yscroll*character_height) % (INTRAFONT_SCREEN_HEIGHT_LINES * line height);
}
}
}
I haven't understand!
What optimize your this code?
If I blit a entire line the speed is a bit different but not enough, maybe I can speed up to 7fps form 6, something like nothing...
Next I doesn't have a monospaced font, intraFont has not a constant width, so...
What I've to check?
What optimize your this code?
If I blit a entire line the speed is a bit different but not enough, maybe I can speed up to 7fps form 6, something like nothing...
Next I doesn't have a monospaced font, intraFont has not a constant width, so...
I haven't understand, sorry.PosX100 wrote:handle the "code" buffer where the text is stored
What I've to check?
Get Xplora!
I don't believe you're only getting 6-7 fps. It's not possible. I've worked on GUIs using intraFont, and they can easily get 60 FPS (not sure how much faster they can go as the gui always limits itself to no faster than the vertical blank rate). You've got something else slowing things down that are unrelated to intraFont.
If you can't understand , then i can't help .ne0h wrote:I haven't understand!
What optimize your this code?
If I blit a entire line the speed is a bit different but not enough, maybe I can speed up to 7fps form 6, something like nothing...
Next I doesn't have a monospaced font, intraFont has not a constant width, so...
I haven't understand, sorry.PosX100 wrote:handle the "code" buffer where the text is stored
What I've to check?
Anyway , if you're getting 6-7 fps :
1)
There's some (more)bad code behind this(judging by your code,its possible)
2)
You're counting fps the WRONG way...
Ok, probably the code have some bugs, but why when I didn't print anything I've 100 "cycle" for second, and when I blit the text I've 10, or less "cycle" for second?
Can I improve the code for getting at least 30 "cycle" for second?
The code has maybe a lot of uneeded thinks, I can try to improve it, but I think that the font blit "section" is slower than the others...
The code that I've posted blit only the needed part of the text, nothing else...
J.F., I use intraFont in the main programm and it doesn't slows down, it's very fast, I don't know why in the text editor is very slow!
I'll try to improve the code, maybe intraFont is not really the main thing that slow down.
Anyway thanks!
Can I improve the code for getting at least 30 "cycle" for second?
The code has maybe a lot of uneeded thinks, I can try to improve it, but I think that the font blit "section" is slower than the others...
The code that I've posted blit only the needed part of the text, nothing else...
J.F., I use intraFont in the main programm and it doesn't slows down, it's very fast, I don't know why in the text editor is very slow!
I'll try to improve the code, maybe intraFont is not really the main thing that slow down.
Anyway thanks!
Get Xplora!
Like PosX100 said, maybe your FPS calculation is off... maybe the values you're getting are REALLY 1000 and 100, not 100 and 10. I can't see how a main loop with nothing going on (since you commented out the main thing) can ONLY get 100 FPS. I can get better than that on Doom with everything going. So either your calculation is off or your code is seriously farged somewhere. One way you can tell for certain is to change your while loop so that instead of running constantly, it instead does X loops and stops - say 600 loops. Time how long the app runs from when it enters the loop until it leaves and divide by 600. If it were really only 10 FPS, it would stay in the loop a minute.
Calculating fps :
#1
Or , per samples:
#2
#3 or per per samples with accurate timing:
#1
Code: Select all
float timePrev = 0.0f;
int fps = 0;
{
const float timeNow = getTimeInMs() *.0001;
//to get the delta for frame IDP games/apps:
//float delta = (timeNow - timePrev);
++fps;
if( timeNow - timePrev > 1.0f )
{
timePrev = timeNow;
fps = 0;
}
}
#2
Code: Select all
static const int FPS_SAMPLES = 48;
static float fpsSamplesBuf[FPS_SAMPLES];
static int currentSample = 0;
static float fps = 0.0f;
void handleFpsSamples(const float delta)
{
fpsSamplesBuf[currentSample % FPS_SAMPLES] = (float)(1.0f / delta);
if(currentSample >= FPS_SAMPLES-1)
{
currentSample = 0;
fps = 0.0f;
for(int i = 0; i<FPS_SAMPLES; i++)
fps += fpsSamplesBuf[i];
if((int)fps)
fps /= FPS_SAMPLES;
}
currentSample++;
}
Code: Select all
static const int FPS_SAMPLES = 48;
static float fpsSamplesBuf[FPS_SAMPLES];
static int currentSample = 0;
static float timePrev = 0.0f;
static float timeNow = 0.0f;
static float delta = 0.0f;
static float fps = 0.0f;
static int updateTimer = 0;
void handleFpsSamples()
{
timeNow = getTimeInMs() *.0001;
delta = (timeNow - timePrev);
timePrev = timeNow;
updateTimer += (int)(delta);
fpsSamplesBuf[currentSample % FPS_SAMPLES] = (float)(1.0f / delta);
if(currentSample >= FPS_SAMPLES-1)
{
currentSample = 0;
fps = 0.0f;
for(int i = 0; i<FPS_SAMPLES; i++)
fps += fpsSamplesBuf[i];
if((int)fps)
fps /= FPS_SAMPLES;
}
if( updateTimer >= 10)
{
updateTimer = 0;
currentSample++;
}
}
Ok, this code works around at 2000 fps
And this around at 200! -.-
The problem is FillScreenRect
( I'm using this function in the windowsmgr ), this is very slow!
This is the code:
What I can do to improve it?
I've also used "sceCtrlPeekBufferPositive", "sceCtrlReadBufferPositive" is more slow, why?
What's the difference between these two functions?
I've also tryied to blit the text with printf, so I can remove flipScreen and Window etc, and I've something like 10000 fps!!!
Anyway now the text editor with all the GUI elements blitted (but no text)
run around 1000 fps...
With text is around 100 fps, so very good!
This what I've done:
TextEditorBlitTextEx:
I've still a lot of things to improve, but the speed now is great!
THE ONLY one problem now I've is how to get the right position
of the cursor!!!
Anyway if I print the entire line is obviously faster that blit each character, sorry!
Thanks very much!
Code: Select all
while(1)
{
XgeClearScreen(WHITE);
intraFontPrintf(40, 40, "%d", cycle++);
XgeScreenReplaceRefresh();
}
Code: Select all
while(1)
{
XgeFillScreenRect(WHITE, 0, 0, 480, 272);
intraFontPrintf(40, 40, "%d", cycle++);
XgeScreenReplaceRefresh();
}
( I'm using this function in the windowsmgr ), this is very slow!
This is the code:
Code: Select all
int skipX = PSP_LINE_SIZE - width;
int x, y;
XgeColor* data = XgeGetVramDrawBuffer() + x0 + y0 * PSP_LINE_SIZE;
for(y = 0; y < height; y++, data += skipX)
{
for(x = 0; x < width; x++, data++)
*data = Color;
}
I've also used "sceCtrlPeekBufferPositive", "sceCtrlReadBufferPositive" is more slow, why?
What's the difference between these two functions?
I've also tryied to blit the text with printf, so I can remove flipScreen and Window etc, and I've something like 10000 fps!!!
Anyway now the text editor with all the GUI elements blitted (but no text)
run around 1000 fps...
With text is around 100 fps, so very good!
This what I've done:
Code: Select all
while(1)
{
sceCtrlPeekBufferPositive(&pad, 1);
ne0h_CtrlReadLatch(&latch);
XgeClearScreen(WHITE);
TextEditorBlitTextEx();
intraFontPrintf(40, 40, "%d", cycle++);
TextEditorBlitTextCursor();
if(danzeff) danzeff_render();
XgeScreenReplaceRefresh();
}
Code: Select all
void TextEditorBlitTextEx()
{
int line_from = Text->first_visible_line;
int line_to = line_from + EDITOR_SCREEN_HEIGHT;
if(line_to > Text->num_lines) line_to = Text->num_lines;
int y = 0;
int real_y = 30;
int line_num;
for(line_num = line_from; line_num < line_to; line_num++)
{
TextLine* line = Text->lines[line_num];
if(line && line->text)
{
if(line->text[0] > ' ')
intraFontPrintf(0, real_y, line->text);
}
y++;
real_y += TextEditorFontHeight;
if(y > INTRAFONT_SCREEN_HEIGHT_LINES) break;
}
}
THE ONLY one problem now I've is how to get the right position
of the cursor!!!
Anyway if I print the entire line is obviously faster that blit each character, sorry!
Thanks very much!
Last edited by ne0h on Sun Dec 14, 2008 1:44 am, edited 1 time in total.
Get Xplora!
Lol...ne0h wrote:oh, yes, this is to estimate the fps...PosX100 wrote:WUT?ne0h wrote:intraFontPrintf(20, 20, "%d", cycle++);
- 10.000 fps
2.000 fps
1.000 fps
200 fps
100 fps
10 fps
7 fps
6 fps
2 fps
(http://www.youtube.com/watch?v=oHg5SJYRHA0).
You have no idea what you're saying ... don't you?.
If you wan't to calculate frames per second correctly , read my previous post.
If you don't wanna learn , i don't really care :-) , but just stop saying that you're calculating FPS...
Ok,PosX100 wrote:You have no idea what you're saying ... don't you?.
If you wan't to calculate frames per second correctly , read my previous post.
If you don't wanna learn , i don't really care :-) , but just stop saying that you're calculating FPS...
I'm calculating how many cycle does the main loop,
it's only estimated by watching the value that is printed on the screen, with that i can see that in one second go from 120 to 130, so I've writed that I've 10fps, if is 11 or 9 is not a problem,
I don't need the exactly measure!
Are different if I've 10fps or 12?? 9 or 8? 1000 or 1021 ?
The main problem is not how many (exactly) fps does the main cycle...
I have others problems to resolve...
Get Xplora!
Yes, it does (but it's ugly). Study the sample provided with intraFont.ne0h wrote:Next I doesn't have a monospaced font, intraFont has not a constant width, so...
The 4th parameter of intraFontSetStyle lets you set the monospace-width, e.g. to 12 pixels:
Code: Select all
intraFontSetStyle(ltn[8], 1.0f,WHITE,BLACK,INTRAFONT_WIDTH_FIX | 12);
Easy, just use intraFontMeasureText to measure the length of the sub-string from the beginning of the line to the current cursor position.ne0h wrote:THE ONLY one problem now I've is how to get the right position of the cursor!!!
Cheers, BenHur
Yes, I've seen this function, ( intraFontMeasure* ) but if I try to measure a string that contains special characters ( like 'è' or 'à' ) I've the lenght of he string form the first char to the firs special char!
I've also tryied intraFontMeasureTextUCS2, but this doesn't measure the "special" char, so I've the lenght of the string without special characters
Anyway I've tryied with fixed with of text on the results if not very good, it's ugly...
So if is possible I'll try to use the standard variable width!
Anyway thanks for intraFont BenHur, it's amazing!
I've also tryied intraFontMeasureTextUCS2, but this doesn't measure the "special" char, so I've the lenght of the string without special characters
Anyway I've tryied with fixed with of text on the results if not very good, it's ugly...
So if is possible I'll try to use the standard variable width!
Anyway thanks for intraFont BenHur, it's amazing!
Get Xplora!
'è' and 'à' are not part of the standard ascii table (0x8A and 0x85), but part of the extended ascii table (which is not supported in intraFont). The corresponding unicode UCS2 values are 0x00E0 and 0x00E8. See:ne0h wrote:Yes, I've seen this function, ( intraFontMeasure* ) but if I try to measure a string that contains special characters ( like 'è' or 'à' ) I've the lenght of he string form the first char to the firs special char!
Code: Select all
http://www.psp-programming.com/benhur/pgf_char_table_ltn0.htm
Since I encountered this issue before, I should add support for the extended ascii table. I'll do it as soon as I find the time...
In the mean-time you can either use text files with a correct UCS2 encoding or do the extended ascii to UCS2 conversion yourself.
Cheers, BenHur
Update:
I released intraFont 0.23, it supports UTF-8 encoded input and a few codepages (currently only 437, 850 and win-1252; let me know if you need others, they're easy to add).
With these features displaying special characters (e.g. Umlaute, accents, ...) should no longer be a problem - if the codepage is set to match the input or UTF-8 encoded input is used.
Cheers, BenHur