Hello!
While working on the flightgear project I have noticed that truetype
fonts sometimes look better if they are rendered in monochrome by the
freetype library. Attached patch contains my preliminary
implementation. Obviously a flag should be added to select render
method, but I have no idea where it fits into the osg framework.
Please help me with this.
Any other comments are welcome as well (a better way to unpack the 1
bpp bitmap returned by freetype, for example).
--
Thanks,
Csaba
Index: src/osgPlugins/freetype/FreeTypeFont.cpp
===================================================================
--- src/osgPlugins/freetype/FreeTypeFont.cpp (revision 7049)
+++ src/osgPlugins/freetype/FreeTypeFont.cpp (working copy)
@@ -105,7 +105,7 @@
}
}
- FT_Error error = FT_Load_Char( _face, charindex,
FT_LOAD_RENDER|FT_LOAD_NO_BITMAP );
+ FT_Error error = FT_Load_Char( _face, charindex,
FT_LOAD_RENDER|FT_LOAD_NO_BITMAP|FT_LOAD_TARGET_MONO );
if (error)
{
osg::notify(osg::WARN) << "FT_Load_Char(...) error "<<error<<std::endl;
@@ -143,13 +143,33 @@
glyph->setInternalTextureFormat(GL_ALPHA);
// copy image across to osgText::Glyph image.
- for(int r=sourceHeight-1;r>=0;--r)
+ switch(glyphslot->bitmap.pixel_mode)
{
- unsigned char* ptr = buffer+r*pitch;
- for(unsigned int c=0;c<sourceWidth;++c,++ptr)
- {
- (*data++)=*ptr;
- }
+ case FT_PIXEL_MODE_MONO:
+ for(int r=sourceHeight-1;r>=0;--r)
+ {
+ unsigned char* ptr = buffer+r*pitch;
+ for(unsigned int c=0;c<sourceWidth;++c)
+ {
+ (*data++) = (ptr[c >> 3] & (1 << (~c & 7))) ? 255 : 0;
+ }
+ }
+ break;
+
+
+ case FT_PIXEL_MODE_GRAY:
+ for(int r=sourceHeight-1;r>=0;--r)
+ {
+ unsigned char* ptr = buffer+r*pitch;
+ for(unsigned int c=0;c<sourceWidth;++c,++ptr)
+ {
+ (*data++)=*ptr;
+ }
+ }
+ break;
+
+ default:
+ osg::notify(osg::WARN) << "FT_Load_Char(...) returned bitmap with
unknown pixel_mode " << glyphslot->bitmap.pixel_mode << std::endl;
}
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/