|
Allegro fonts in AllegroGL |
james_lohr
Member #1,947
February 2002
|
I've just finished writing a few useful functions for displaying allegro fonts in AllegroGL. (AllegroGL's font drawing routines are not working for displaying textured allegro fonts in anything other than monochrome). If anyone else is having the same problem, you may find this very useful. Here are the function prototypes: JFONT *create_jfont(FONT *fnt);This generates a font from an allegro font. FONT *fnt must be an allegro font. void destroy_jfont(JFONT *jfont);Destroys the generated font, deleting OpenGL textures. void jprintf(JFONT *f, float x, float y, float z,float scale, char *format, ...);Draws the text as a series of quads (printf style). OpenGL's matrix transformations must be set appropriately before the text is drawn. There , nice and simple. (note: the blurring around the edges is 'cause this is a .jpg screenshot.) JFONT *create_jfont(FONT *fnt) is actually quite complicated. It uses a packing algorithm to fit the glyphs into an appropriately sized texture: Allegro font: (before packing) OpenGL (2^n,2^m) texture after packing: I won't post the code now, but if anyone wants it, I'll neaten it up a bit. (I can't be bothered at the moment 'cause, no doubt, Bob'll fix the problem tomorrow and all this will be a waste of time ) Gnatinator: Thanks for your code, I found it useful for writing my own functions.
|
Bob
Free Market Evangelist
September 2000
|
The other option would have been to send me a patch for AllegroGL... -- |
james_lohr
Member #1,947
February 2002
|
That's what I spent the better part of today trying to do, but I just couldn't get my head around all your code let alone actually find the problem. I'll give it another go over the weekend if you like . Or maybe you could fix it ? Seriously I'm sure it would take you a tenth of the time it would take me... Well if it is fixable (I gave up earlier today mainly because I was worried that it was an OpenGL limitation and not a bug) I don't mind trying again. It'd do me a lot of good to go through it all in detail, I'm sure .
|
Kitty Cat
Member #2,815
October 2002
|
It looks good to me.. although you may want to, when creating the OpenGL texture, make it have as few vertical rows as possible and put a transparant pixel or two in between the glyphs. This will help when using linear filtering. Though I would think it'd be better to just fix AllegroGL. -- |
james_lohr
Member #1,947
February 2002
|
Quote: make it have as few vertical rows as possible I don't understand . Quote: put a transparant pixel or two in between the glyphs Already done.
|
Kitty Cat
Member #2,815
October 2002
|
Put as many glyphs on a single vertical row as possible. The fewer vertical rows you have, the less padding there'll be. More space-efficient. -- |
james_lohr
Member #1,947
February 2002
|
The packing algorith I'm using doesn't work like that. If you look closely you'll see that there are no columns (vertical rows). The reason why there is padding at the bottom is because the OpenGL texture must be (2^n,2^m). [EDIT] Implemented gradients for monochrone fonts. Look'n' pretty . These are drawn with the same monochrone font:
|
Gnatinator
Member #2,330
May 2002
|
Looking good! Im glad to finally see a complete solution to the problem. Quote: Gnatinator: Thanks for your code, I found it useful for writing my own functions. Hey hey, no problem Quote: These are drawn with the same monochrone font... Cant see the picture
|
Bob
Free Market Evangelist
September 2000
|
Gnatinator: I wonder if your texture packing code is better than AllegroGL's. If it is, and is also simpler, then it might be a good replacement. -- |
Gnatinator
Member #2,330
May 2002
|
Quote: Gnatinator: I wonder if your texture packing code is better than AllegroGL's. If it is, and is also simpler, then it might be a good replacement. Heh, the texture isnt packed or unpacked. The code just loads a tga texture, cuts it up and displays characters according to the parameters you give the function. If you want my code check out my post here. The disadvantage to my system is that the font is displayed in quads of all the same size. So unless all your characters are the same width, your going to have a slight change of distance between each char. At the moment I have a parameter that will adjust character distance and for now I just use that which is kind of a temporary fix.
|
Thomas Fjellstrom
Member #476
June 2000
|
The texture you posted shows characters of varying width, just use those widths. no? -- |
Gnatinator
Member #2,330
May 2002
|
In that font (the parameters on the function could accomidate any char w/h as long as all are constant) the chars have 16 pixel hieght and 16 width box surrounding them. The function just blits that 16x16 box for whatever char you need, sometimes creating a little extra space. EDIT:
|
Thomas Fjellstrom
Member #476
June 2000
|
Actually, You'll have to excuse me I was thinking about the one James posted the one all packed together. -- |
james_lohr
Member #1,947
February 2002
|
This is the second time I've been confused with someone else also using a greyscale avatar in the same thread as me . My code stores character offsets during packing so that the text is drawn exactly as it would look if drawn with allegro's text functions. It also means that it is faster because the quads are only as big as they need to be. For example here's some text with texturing disabled to give you an idea of the quad size: [Edit]
|
Gnatinator
Member #2,330
May 2002
|
Hey James maybe you could upload your code?
|
james_lohr
Member #1,947
February 2002
|
Ok, just need some time to neaten it up a bit (add indents and some comments etc. ). [EDIT] Bob said: I wonder if your texture packing code is better than AllegroGL's. If it is, and is also simpler, then it might be a good replacement. Pahahahah. I'm almost too embarrassed to show my code it's such a mess. Sorry, there's not a hope in hell of anything I've written replacing your professional code. All this is meant to be is something hacky that works until someone fixes AllegrGL. I wish I had the ability to fix it, but unfortunately it's beyond me. So here it is: jfont.h
jfont.c is attatched 'cause it's too big. [EDIT 2] - fixed bug: create_jfont() was not working if allegro_gl_flip_texture() was set incorrectly. Now it works whatever allegro_gl_flip_texture() is set to and restores original value.
|
|