| View previous topic :: View next topic |
| Author |
Message |
ADePSP
Joined: 13 Jul 2006 Posts: 58
|
Posted: Sun Jul 16, 2006 10:59 pm Post subject: 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
Last edited by ADePSP on Thu Jul 20, 2006 6:59 am; edited 1 time in total |
|
| Back to top |
|
 |
Kojima
Joined: 26 Jun 2006 Posts: 275
|
Posted: Sun Jul 16, 2006 11:27 pm Post subject: |
|
|
Here's a pspgl font engine I use, the texture class just creates a gl texture, which i'm sure you can manage.
| Code: |
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;
};
|
|
|
| Back to top |
|
 |
ADePSP
Joined: 13 Jul 2006 Posts: 58
|
Posted: Sun Jul 16, 2006 11:48 pm Post subject: |
|
|
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 |
|
| Back to top |
|
 |
Kojima
Joined: 26 Jun 2006 Posts: 275
|
Posted: Mon Jul 17, 2006 12:14 am Post subject: |
|
|
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. |
|
| Back to top |
|
 |
Jim

Joined: 02 Jul 2005 Posts: 487 Location: Sydney
|
Posted: Mon Jul 17, 2006 9:13 am Post subject: |
|
|
| Quote: | | I'm not sure if psp sdk can mix and match C++ and C |
It definitely can.
Jim _________________ http://www.dbfinteractive.com |
|
| Back to top |
|
 |
ADePSP
Joined: 13 Jul 2006 Posts: 58
|
Posted: Tue Jul 18, 2006 12:15 am Post subject: |
|
|
| Jim wrote: | | Quote: | | I'm not sure if psp sdk can mix and match C++ and C |
It definitely can.
Jim |
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...
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/floating/699/ft09c.zip |
|
| Back to top |
|
 |
dot_blank

Joined: 28 Sep 2005 Posts: 498 Location: Brasil
|
|
| Back to top |
|
 |
Jim

Joined: 02 Jul 2005 Posts: 487 Location: Sydney
|
Posted: Wed Jul 19, 2006 5:49 pm Post subject: |
|
|
| Quote: | | 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... |
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.
Jim _________________ http://www.dbfinteractive.com |
|
| Back to top |
|
 |
ector
Joined: 12 May 2005 Posts: 195
|
Posted: Wed Jul 19, 2006 6:26 pm Post subject: |
|
|
| 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.
|
You could pull glBegin/glEnd out of that loop and instantly maybe double your speed... _________________ http://www.dtek.chalmers.se/~tronic/PSPTexTool.zip Free texture converter for PSP with source. More to come. |
|
| Back to top |
|
 |
ADePSP
Joined: 13 Jul 2006 Posts: 58
|
Posted: Wed Jul 19, 2006 9:03 pm Post subject: |
|
|
| Jim wrote: | | Quote: | | 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... |
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.
Jim |
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...
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 |
|
| Back to top |
|
 |
ADePSP
Joined: 13 Jul 2006 Posts: 58
|
Posted: Wed Jul 19, 2006 10:26 pm Post subject: The SOLUTION!!! |
|
|
Well, whoever said "if you want something doing, do it yourself" was correct...
I have fixed the flib code created by samedi1971@yahoo.com 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 |
|
| Back to top |
|
 |
dot_blank

Joined: 28 Sep 2005 Posts: 498 Location: Brasil
|
Posted: Thu Jul 20, 2006 2:01 am Post subject: |
|
|
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 _________________ 10011011 00101010 11010111 10001001 10111010 |
|
| Back to top |
|
 |
ADePSP
Joined: 13 Jul 2006 Posts: 58
|
Posted: Thu Jul 20, 2006 6:56 am Post subject: |
|
|
| 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 |
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...
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: | 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(); |
Obviously that is more pseudo code than a working example but that looks pretty stright forward for new developers to use for me...
ADe |
|
| Back to top |
|
 |
dot_blank

Joined: 28 Sep 2005 Posts: 498 Location: Brasil
|
Posted: Thu Jul 20, 2006 7:53 am Post subject: |
|
|
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 _________________ 10011011 00101010 11010111 10001001 10111010 |
|
| Back to top |
|
 |
ADePSP
Joined: 13 Jul 2006 Posts: 58
|
Posted: Thu Jul 20, 2006 8:46 am Post subject: |
|
|
| 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 |
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...
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... :( |
|
| Back to top |
|
 |
dot_blank

Joined: 28 Sep 2005 Posts: 498 Location: Brasil
|
Posted: Thu Jul 20, 2006 12:09 pm Post subject: |
|
|
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 _________________ 10011011 00101010 11010111 10001001 10111010 |
|
| Back to top |
|
 |
Kojima
Joined: 26 Jun 2006 Posts: 275
|
Posted: Thu Jul 20, 2006 9:15 pm Post subject: |
|
|
| ector wrote: | | 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.
|
You could pull glBegin/glEnd out of that loop and instantly maybe double your speed... |
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.
I guess I could use tris as they don't have similar problems I hear. |
|
| Back to top |
|
 |
Jim

Joined: 02 Jul 2005 Posts: 487 Location: Sydney
|
Posted: Thu Jul 20, 2006 9:19 pm Post subject: |
|
|
Because you used GL_QUADS. You can only render one quad at a time with PSPGL - it's not implemented.
Jim _________________ http://www.dbfinteractive.com |
|
| Back to top |
|
 |
ADePSP
Joined: 13 Jul 2006 Posts: 58
|
Posted: Fri Jul 21, 2006 12:28 am Post subject: |
|
|
| 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 |
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...?
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 |
|
| Back to top |
|
 |
Kojima
Joined: 26 Jun 2006 Posts: 275
|
Posted: Fri Jul 21, 2006 2:09 am Post subject: |
|
|
| Jim wrote: | Because you used GL_QUADS. You can only render one quad at a time with PSPGL - it's not implemented.
Jim |
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.
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. |
|
| Back to top |
|
 |
ADePSP
Joined: 13 Jul 2006 Posts: 58
|
Posted: Fri Aug 25, 2006 2:55 am Post subject: |
|
|
| 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 |
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)...
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 |
|
| Back to top |
|
 |
Art
Joined: 09 Nov 2005 Posts: 647
|
Posted: Sun Jun 17, 2007 5:25 pm Post subject: |
|
|
| nvm. |
|
| Back to top |
|
 |
everlasting
Joined: 19 Mar 2007 Posts: 41
|
Posted: Tue Jun 19, 2007 9:34 pm Post subject: |
|
|
| Quote: | | Does the font have to be a specific size or something or maybe you have to change the code to specify the size...? |
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.
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... |
|
| Back to top |
|
 |
kasikeeper
Joined: 29 Nov 2007 Posts: 36
|
Posted: Mon Feb 25, 2008 5:38 am Post subject: |
|
|
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 |
|
| Back to top |
|
 |
Vincent_M
Joined: 03 Apr 2007 Posts: 73
|
Posted: Wed Feb 27, 2008 3:51 am Post subject: |
|
|
| You know, you could always just use pgeFont or intraFont. Both of them are totally open-source, and intraFont is built from pgeFont. They are both really good except that intraFont doesn't use freetype from what I've been told. I'm only using pgeFont because I have modified it right now. |
|
| Back to top |
|
 |
kasikeeper
Joined: 29 Nov 2007 Posts: 36
|
Posted: Thu Feb 28, 2008 6:47 am Post subject: |
|
|
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: |
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 |
|
|
| Back to top |
|
 |
|