Please help me conceptually with extended character support

Member
Posts: 204
Joined: 2002.09
Post: #16
Regardless of standards, bottom-line is that if it does everything you want then it doesn't matter. No point disparaging a good screwdriver simply because it doesn't include a hammer and pocket knife as well.


If you're still interesting in releasing this, I'm still interested in looking at it Grin
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #17
Sure thing:

http://zakariya.net/shamyl/etc/GlyphGen.zip

The zip file is for an Xcode 2.2 project ( universal binary, but untested since I have a g4 only ). It builds a Cocoa app, "GlyphGen" which lets you select your font family, face, and point size. It lets you view the glyphs and a render preview. When you have a selection you like, just command-s to save. It saves two files, an 8-bit PNG, and a "metrics" file. They're given the same filename, just with different extensions ( ".png", and ".metrics" ).

If you're interested in using it, by all means! But as of now, it depends on Cocoa and OS X for a few bits. You can see the usage of the Font class in GlyphRenderView.mm.

The files you'll need for rendering are: Font.{h/mm}, GlyphMetrics.{h/mm}, GlyphMetricsEntry.h and UTF8ToUnichar.h

If you want to eliminate Cocoa dependence, you'll want to yank the code from GlyphMetrics -initWithFile: (NSString *) and put that code in Font::load -- it's simple, just a bunch of calls to fread() with byteswapping for endian safety. You'll also want to drop the use of the CoreServices endian functions for whatever endian functions/macros you have. When that's done, the Font class can be pure C++, instead of ObjC++.

Finally, I'm using my own texture loader, which uses CoreGraphics for 8-bit greyscale images, and Quicktime for 32-bit ( since quicktime thankfully doesn't premultiply ). It would be easy enough to use whatever texture loading code/libs you prefer. The only important detail is that the font texture is an 8-bit greyscale image, being used as a GL_ALPHA texture.

Anyway, the app's quick and dirty, but does the job. And the Font class is easy to use. Just load a font and call render( const char *utf8string, vec2i origin, vec4 color ).

I've got several rendering variants so you can render std::string, and arrays of std::string at arrays of 2d points. Also, I provide three different bounds calculation algorithms: one to calculate the logical bounds using cap-height and per-char advance, one to calculate the bounds using ascent + descent and the per-char advance, and one which returns the rectangle containing all the pixels which would be rendered to.

Let me know if you have any questions, or bugs, or if you see some way to make it better!
Quote this message in a reply
Sage
Posts: 1,234
Joined: 2002.10
Post: #18
TomorrowPlusX Wrote:bugs
You are trusting the reported metrics Wink

Your bounding box for each glyph extends a pixel or three beyond the actual rasterized pixels, which means your bin packing won't be as great as it could be.

When I did this sort of app I just rasterized the glyph and iterated over the pixels to find the real bounds.

I also used the font picker... Wink
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #19
Very true. I had a lot of trouble, actually, with reported metrics but the approach I took, instead of querying pixels in a buffer was to convert the glyphs into bezier paths and use the rect containing the path for the bounding box. I had to expand that rect by couple pixels, however...

In retrospect, I should probably have rasterized the bezier path instead of using the path for bounding, than using the NSString drawAtPoint method. It's more than likely that NSBezierPath will raster slightly differently than ATSUI. Good news is I can fix this in GlyphGen without having to touch the actual font rendering code, since all that really matters is that the right data is pumped into the metrics file.

Quote:I also used the font picker...

Yeah. An early layout of GlyphGen used the font picker, but I actually prefer, from a GUI standpoint, the approach I'm using with two menus. I know I should leverage what OS X offers, but I found this particular approach to be cleaner, in this context. Of course, because of that, I don't have collections. So be it, this app is meant to be simple, not a masterpiece of Cocoa programming!
Quote this message in a reply
Member
Posts: 144
Joined: 2004.07
Post: #20
Urg, I'm getting into heavy GUI stuff in my engine using FTGL and I to am starting to feel the performance burn of FTGL.

I don't think I'll have much choice but to transition over to your code (there's no way I'll do a better job at writing this then you will). What license do you want to attach with that code? How much more work do you think it'll undergo? (in other words, how long should I wait until I try to shoe-horn it into my engine)

For now I'm going to swallow the performance hit, but soon I'll take the time to move it over. Thanks, but urg.

EDIT: After probing FTGL's source I've found the texture font rendering code uses glPushAttrib()/glPopAttrib() each frame. With some cleanup I got some performance back and I'm content with FTGL again. Down the road I'll look at speeding up FTGL even more (after more in-depth profiling and tweaking) or going with what I can find out there (perhaps yours).

For reference here's the cleaned up code (it stuck out like a sore thumb):
Code:
void FTGLTextureFont::Render( const char* string)
{  
//    glPushAttrib( GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT);
//    
//    glEnable(GL_BLEND);
//    glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // GL_ONE

    FTTextureGlyph::ResetActiveTexture();
    
    FTFont::Render( string);
//
//    glPopAttrib();
}
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #21
That's *interesting*. glPush/Pop Attrib seems universally to cause performance problems.

That said:

Quote:I don't think I'll have much choice but to transition over to your code (there's no way I'll do a better job at writing this then you will).

I appreciate the sentiment, but I'm *sure* my code could be improved, be it for performance or for robustness.

My qualms with my code, ATM, is that it doesn't pack glyphs as tightly as it could, so the texture ends up a little larger than it could be. Secondly, that my Font class requires cocoa to load the metrics file. Honestly, it would be all of 10 minutes work to resolve that. If you're concerned about license, consider it public domain, but if you do use it, I'd appreciate a mention in the readme or whatever. Nothing more. Well, unless your location "Your backyard" happens to be in or around the Washington DC area, in which case you could buy me a beer.

I wish DC were like the SF Bay Area, where Mac programmers meet up for beers and pizza for fun. All the programmers around here are Java, working for the defence sector. Not a fun bunch...
Quote this message in a reply
Member
Posts: 204
Joined: 2002.09
Post: #22
TomorrowPlusX Wrote:I wish DC were like the SF Bay Area, where Mac programmers meet up for beers and pizza for fun. All the programmers around here are Java, working for the defence sector. Not a fun bunch...

Well, not ALL of them ;-)

I'm not even 45 minutes from northern DC. Of course, its not like we have a local branch of the IGDA or anything.
Quote this message in a reply
Apprentice
Posts: 6
Joined: 2006.03
Post: #23
TomorrowPlusX, you should post a screenshot of that white font on black background, the smaller font chooser/stress tester with the custom UI you rolled. The fullscreen one. That looked fantastic. I love how your demos are programmatically and aesthetically pleasing all at the same time (although I can only quickly pick up on the later).
Quote this message in a reply
Apprentice
Posts: 6
Joined: 2006.03
Post: #24
TomorrowPlusX Wrote:I wish DC were like the SF Bay Area, where Mac programmers meet up for beers and pizza for fun. All the programmers around here are Java, working for the defence sector. Not a fun bunch...

That post makes me sad. Just give me a damn call for pizza and beer and I'll talk all you want about non-app stuff. Send message for cell number...
Quote this message in a reply
Moderator
Posts: 1,562
Joined: 2003.10
Post: #25
Hey, if you guys are meeting up for pizza and beer, I'd be interested in joining you. I'm only an hour or two from DC. Could be a lot of fun. Smile
Quote this message in a reply
Member
Posts: 204
Joined: 2002.09
Post: #26
KittyMac Wrote:I'm not even 45 minutes from northern DC.

ThemsAllTook Wrote:Hey, if you guys are meeting up for pizza and beer, I'd be interested in joining you. I'm only an hour or two from DC. Could be a lot of fun.

I'm game for that if its before June 9. After that I'm moving to the Atlanta, GA area.
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #27
milkfilk Wrote:That post makes me sad. Just give me a damn call for pizza and beer and I'll talk all you want about non-app stuff. Send message for cell number...

Oh my god -- it's you from the coffee shop!
Quote this message in a reply
Post Reply