Fonts: Please Help... (UPDATED) The Easy Solution - Read On
Fonts: Please Help... (UPDATED) The Easy Solution - Read On
Hi,
I'm having major problems with fonts... I'm using cygwin and C to write my app and need to use a better font than the horrible default one...
I've tried FreeType but it seems to load each character from the memstick each time which is really slowing my program down to an unusable level...
What do other people here use...?
ADe
I'm having major problems with fonts... I'm using cygwin and C to write my app and need to use a better font than the horrible default one...
I've tried FreeType but it seems to load each character from the memstick each time which is really slowing my program down to an unusable level...
What do other people here use...?
ADe
Last edited by ADePSP on Thu Jul 20, 2006 6:59 am, edited 1 time in total.
Here's a pspgl font engine I use, the texture class just creates a gl texture, which i'm sure you can manage.
Code: Select all
class Font
{
public:
Font(char * file,float charwidth=32,float charheight=32,float charsperline=16,float xinc=10)
{
_tex = new Texture(file,BMP);
_cw = charwidth;
_ch = charheight;
_mw = _tex->_w;
_mh = _tex->_h;
_xinc = xinc;
_cpl = charsperline;
}
float _cw,_ch;
float _mw,_mh,_cpl,_xinc;
Texture *_tex;
};
class FontEngine
{
public:
FontEngine()
{
_active = NULL;
_r = 1;
_g = 1;
_b = 1;
}
void SetActive(Font *font)
{
_active = font;
}
void SetColor(float r,float g,float b)
{
_r=r;
_g=g;
_b=b;
}
int TextWidth( char * txt )
{
int l = TextLen( txt )*_active->_xinc;
return l;
}
int TextHeight()
{
return _active->_ch;
}
int TextLen( char * txt )
{
int c = 0;
while(1)
{
if( txt[c] == 0 ) break;
c++;
}
return c;
}
void RenderText(float x,float y,char *txt)
{
int cc=0;
int chr;
Blend_Mask();
glEnable(GL_TEXTURE_2D);
_active->_tex->Bind();
float dx,dy;
dx = x;
dy = 272-y;
while(1)
{
chr = txt[cc];
if( chr == 0 ) break;
int xo,yo;
yo = (chr/(int)_active->_cpl);
xo = (chr-(yo *(int) _active->_cpl ));
float ax,ay;
ax = xo * _active->_cw;
ay = yo * _active->_ch;
float ex,ey;
ex = ax + _active->_cw;
ey = ay + _active->_ch;
float u0,v0,u1,v1;
u0 = ax / _active->_mw;
v0 = 1-(ay / _active->_mh);
u1 = ex / _active->_mw;
v1 = 1-(ey / _active->_mh);
glBegin(GL_QUADS);
glTexCoord2f( u0,v0 );
glVertex2f( dx,dy );
glTexCoord2f( u1,v0 );
glVertex2f( dx+_active->_cw,dy );
glTexCoord2f( u1,v1 );
glVertex2f( dx+_active->_cw,dy-_active->_ch );
glTexCoord2f( u0,v1 );
glVertex2f( dx,dy-_active->_ch );
glEnd();
dx += _active->_xinc;
cc++;
}
_active->_tex->Unbind();
glDisable(GL_TEXTURE_2D);
}
float _r,_g,_b;
Font *_active;
};
Sorry to be a dum ass but i've never used C classes before... I assume I put this in a .cpp file but then need to include it in my main.c file somehow... If you could explain how to do all that then i'm sure I can work out the useage from the other Pvf sample you gave me before...
Oh, also, do I need to svn any modules down to cygwin to use this...?
Thanks again for all your help...
ADe
Oh, also, do I need to svn any modules down to cygwin to use this...?
Thanks again for all your help...
ADe
I'm not sure if psp sdk can mix and match C++ and C, but you can always try. Personally I just use C++ exclusively without problems. (Be sure to turn off o2 optimization though, it can muck C++ up in my experierence. )
Once you're using C++, it's simply a case of using the classes. The font texture is just a 512x512 texture containing 255 characters, in the order of ascii keycodes.
Once you're using C++, it's simply a case of using the classes. The font texture is just a 512x512 texture containing 255 characters, in the order of ascii keycodes.
How do I use this .cpp file...? Do I just include it in my main.c or what...? I'm a bit lost with all this...Jim wrote:It definitely can.I'm not sure if psp sdk can mix and match C++ and C
Jim
Thanks
ADe
EDIT: Also where do I get the bmp files with the font characters in them or do I have to make my own from scratch...?
EDIT2: I found this free font converter which will create bitmaps from true type font files... Most of these converters cost money so I thought i'd post a link to this one to save other people the time searching,
http://www.fortunecity.co.uk/skyscraper ... /ft09c.zip
Obviously not. Anyway, the whole Texture class is missing so it's not much use on its own. Why don't you start with something simpler if you don't know what you're doing? You're starting at the hard end.How do I use this .cpp file...? Do I just include it in my main.c or what...? I'm a bit lost with all this...
Jim
You could pull glBegin/glEnd out of that loop and instantly maybe double your speed...Kojima wrote:Here's a pspgl font engine I use, the texture class just creates a gl texture, which i'm sure you can manage.
http://www.dtek.chalmers.se/~tronic/PSPTexTool.zip Free texture converter for PSP with source. More to come.
I work as a software developer and can program comfortably in Visual Basic, ASP, Perl, PHP and Borland Delphi... The thing is i've only done a little bit of C++ before... So basically, i'm more than capable of learning quickly...Jim wrote:Obviously not. Anyway, the whole Texture class is missing so it's not much use on its own. Why don't you start with something simpler if you don't know what you're doing? You're starting at the hard end.How do I use this .cpp file...? Do I just include it in my main.c or what...? I'm a bit lost with all this...
Jim
Currently my program is working well apart from the font speed... I'm finding it quite frustrating that nobody can give me an example of a program that can use a font other than the system one... I would have thought this was a simple request...
ADe
The SOLUTION!!!
Well, whoever said "if you want something doing, do it yourself" was correct...
I have fixed the flib code created by [email protected] to load True Type fonts into memory before attaching to them rather than off the memory stick. This means that it now loads each character from memory also when the fonts are rendered... This has obviously speeded it up massivly and fixed the limitation in the original code...
This is now the best and easiest font solution i've found for the PSP so if anyone wants to have a look please download the source with included example...
http://www.cheatsync.net/flib.rar
Cheers
ADePSP
I have fixed the flib code created by [email protected] to load True Type fonts into memory before attaching to them rather than off the memory stick. This means that it now loads each character from memory also when the fonts are rendered... This has obviously speeded it up massivly and fixed the limitation in the original code...
This is now the best and easiest font solution i've found for the PSP so if anyone wants to have a look please download the source with included example...
http://www.cheatsync.net/flib.rar
Cheers
ADePSP
Yeah, I saw that sample but the creation of the font file in that raw format stopped me in my tracks and I wasn't sure if these bitmap style fonts where fixed width which looks rubbish if you ask me...dot_blank wrote:it is also worth noting that there has been a GU
texture font sample in samples/dir for some time now
it is small it is simple it is fast ....a more efficient
means of drawing glyph fonts instead of using the fat
obese freetype library
I'm sure the code I changed is certainly not as effectient as these type of fonts but don't knock it until you've tried it...
How can anything be easier than this,
Code: Select all
load_font("arial.ttf");
set_font_color(0xffffffff);
set_font_size(12);
set_font_angle(0.0);
text_to_screen("HELLO WORLD:", 280, 136);
unload_font();
ADe
Depends what kind of app you are writing... Sometimes "simple and small and fast" is best and sometimes (and in my case) quality is far more important...dot_blank wrote:that has nothing to do with the efficiency of the font
anyone can write their own font wrapper funcs
but in the end your still using freetypes bloated
library and that goes against what i tried to tell you
as going for simple and small and fast
EDIT: Also, if people would just post easy to use examples of other methods of using fonts etc. then that would be extremely helpful to new people... It doesn't have to be hard if people would just post examples... :(
quality can come in small sizes :)
http://www.lmnopc.com/bitmapfontbuilder/
its pretty straight forward to convert
a freetype truetype font into a bitmap
with this great converter tool and its
very useful ...you can easily edit font
sample to use your own converted font
http://www.lmnopc.com/bitmapfontbuilder/
its pretty straight forward to convert
a freetype truetype font into a bitmap
with this great converter tool and its
very useful ...you can easily edit font
sample to use your own converted font
10011011 00101010 11010111 10001001 10111010
That is how I dd it on my pc engine of the same name, but in pspgl doing so causes the texture coords to mess up. All distorted and of no real use, but as soon as I changed it to how it is, it worked fine in pspgl.ector wrote:You could pull glBegin/glEnd out of that loop and instantly maybe double your speed...Kojima wrote:Here's a pspgl font engine I use, the texture class just creates a gl texture, which i'm sure you can manage.
I guess I could use tris as they don't have similar problems I hear.
I stand corrected it does display them correctly... One question though...? I used that program you linked to and exported a font in raw format and replaced the gu\text\font.raw file with it and then compiled the program... It just displayed junk all over the screen... Does the font have to be a specific size or something or maybe you have to change the code to specify the size...?dot_blank wrote:quality can come in small sizes :)
http://www.lmnopc.com/bitmapfontbuilder/
its pretty straight forward to convert
a freetype truetype font into a bitmap
with this great converter tool and its
very useful ...you can easily edit font
sample to use your own converted font
Anyway, if you help me with this I might just go through my app and use this method if it is as fast as you say...
Cheers
ADe
Yeah tbh it would be better to disable the functionality it presently has, because it's not entirely unimplemented. It will render multiple quads at the coordinates you specify, it just has funky texture uv'ing.Jim wrote:Because you used GL_QUADS. You can only render one quad at a time with PSPGL - it's not implemented.
Jim
If it wasn't for a post I saw on these boards (Or eventually the pspgl source I guess) I would have been tearing my source apart for the bug.
I've used this utility to create a font in raw format but it wont display... All I have done is replace the font.raw file in the example with my one but there must be something else I need to do (in the code maybe)...dot_blank wrote:quality can come in small sizes :)
http://www.lmnopc.com/bitmapfontbuilder/
its pretty straight forward to convert
a freetype truetype font into a bitmap
with this great converter tool and its
very useful ...you can easily edit font
sample to use your own converted font
If anyone can help I would really appretiate it because the freetype method is far too slow for what I want to do next...
Thanks in advance...
ADe
-
- Posts: 41
- Joined: Mon Mar 19, 2007 6:27 pm
I'm pretty sure it does. I've been working a little on this example, and it seems that the hight must be 16 and the widht between 6 and 14 if i remember well.So you will have to adjust the font size.Does the font have to be a specific size or something or maybe you have to change the code to specify the size...?
About the discusion, from my point of view the best solution would be to be able to put a ttf font on the psp and that in an inizialation method the psp would convert it into a bitmap font, in the same way the pc programme does. I already had a look at the source code of that programme a few weeks ago, but due to lack of time i haven't started to work with it. I was thinking about making a mini-port of it to the psp with the purpose i explained before. If anyone could tell me if this is possible...
-
- Posts: 36
- Joined: Thu Nov 29, 2007 7:08 pm
Hi,
I was trying to use the simple example given at
http://www.cheatsync.net/flib.rar
but I realized I haven't got the freetype library. Now, I am not using Cygwin to compile the toolchain files myself. Can anyone send the compiled freetype libraries please?
Thanks a lot,
Kai
I was trying to use the simple example given at
http://www.cheatsync.net/flib.rar
but I realized I haven't got the freetype library. Now, I am not using Cygwin to compile the toolchain files myself. Can anyone send the compiled freetype libraries please?
Thanks a lot,
Kai
-
- Posts: 36
- Joined: Thu Nov 29, 2007 7:08 pm
Ok, I managed to compile the FLIB example, although I had to adjust the makefiletoget it work with my setup. The problem is, however, that noting is displayed on my PSP. I am using CFW3.90-2 and this is my modified makefile - anything else remained the same. Can anyone help?
Code: Select all
TARGET = flibtest
OBJS = flibtest.o flib.o graphics.o framebuffer.o
INCDIR =
CFLAGS = -G0 -Wall -O2 -I"C:/pspsdk/INCLUDE" -I"C:/pspsdk/INCLUDE/freetype2"
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
LIBDIR = "C:/pspsdk/lib"
LDFLAGS =
LIBS= -lpsppower -lpspgu -lpng -lz -lm -lfreetype
EXTRA_TARGETS = EBOOT.PBP kxploit
PSP_EBOOT_TITLE = Font library demo
cat $1 | sed 's/PSPSDK.*=.*$(shell psp-config --pspsdk-path)/# PSPSDK MUST BE AN ENV VAR/' > $1
include $(PSPSDK)/lib/build.mak