diff --git a/include/osgText/Font b/include/osgText/Font index a6ca7c345..af2bdf762 100644 --- a/include/osgText/Font +++ b/include/osgText/Font @@ -25,6 +25,8 @@ #include +//#define OSG_FONT_USE_LUMINANCE_ALPHA + namespace osgText { class Font; diff --git a/src/osgPlugins/freetype/FreeTypeFont.cpp b/src/osgPlugins/freetype/FreeTypeFont.cpp index aa274d69a..f7e4510f1 100644 --- a/src/osgPlugins/freetype/FreeTypeFont.cpp +++ b/src/osgPlugins/freetype/FreeTypeFont.cpp @@ -80,9 +80,7 @@ osgText::Font::Glyph* FreeTypeFont::getGlyph(unsigned int charcode) osg::ref_ptr glyph = new osgText::Font::Glyph; - -//#define USE_LUMINANCE_ALPHA -#ifdef USE_LUMINANCE_ALPHA +#ifdef OSG_FONT_USE_LUMINANCE_ALPHA unsigned int dataSize = width*height*2; unsigned char* data = new unsigned char[dataSize]; @@ -97,6 +95,8 @@ osgText::Font::Glyph* FreeTypeFont::getGlyph(unsigned int charcode) osg::Image::USE_NEW_DELETE, 1); + glyph->setInternalTextureFormat(GL_LUMINANCE_ALPHA); + // skip the top margin data += (margin*width)*2; diff --git a/src/osgText/DefaultFont.cpp b/src/osgText/DefaultFont.cpp index 9f0fed4fa..b94fb49ca 100644 --- a/src/osgText/DefaultFont.cpp +++ b/src/osgText/DefaultFont.cpp @@ -195,8 +195,7 @@ void DefaultFont::constructGlyphs() unsigned int sourceWidth = 8; unsigned int sourceHeight = 12; -//#define USE_LUMINANCE_ALPHA -#ifdef USE_LUMINANCE_ALPHA +#ifdef OSG_FONT_USE_LUMINANCE_ALPHA _width = sourceWidth+2*_margin; _height = sourceHeight+2*_margin; diff --git a/src/osgText/Font.cpp b/src/osgText/Font.cpp index edc99f6de..bc732ec24 100644 --- a/src/osgText/Font.cpp +++ b/src/osgText/Font.cpp @@ -89,7 +89,11 @@ Font::Font(FontImplementation* implementation): _magFilterHint(osg::Texture::LINEAR) { setImplementation(implementation); +#ifdef OSG_FONT_USE_LUMINANCE_ALPHA + _texEnv = new osg::TexEnv(osg::TexEnv::MODULATE); +#else _texEnv = new osg::TexEnv(osg::TexEnv::BLEND); +#endif } Font::~Font() @@ -400,9 +404,13 @@ void Font::GlyphTexture::apply(osg::State& state) const // being bound for the first time, need to allocate the texture +#ifdef OSG_FONT_USE_LUMINANCE_ALPHA _textureObjectBuffer[contextID] = textureObject = getTextureObjectManager()->reuseOrGenerateTextureObject( contextID,GL_TEXTURE_2D,1,GL_LUMINANCE_ALPHA,getTextureWidth(), getTextureHeight(),1,0); - +#else + _textureObjectBuffer[contextID] = textureObject = getTextureObjectManager()->reuseOrGenerateTextureObject( + contextID,GL_TEXTURE_2D,1,GL_ALPHA,getTextureWidth(), getTextureHeight(),1,0); +#endif textureObject->bind(); @@ -428,12 +436,19 @@ void Font::GlyphTexture::apply(osg::State& state) const } // allocate the texture memory. +#ifdef OSG_FONT_USE_LUMINANCE_ALPHA glTexImage2D( GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, getTextureWidth(), getTextureHeight(), 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, 0 ); - +#else + glTexImage2D( GL_TEXTURE_2D, 0, GL_ALPHA, + getTextureWidth(), getTextureHeight(), 0, + GL_ALPHA, + GL_UNSIGNED_BYTE, + 0 ); +#endif } else @@ -514,6 +529,7 @@ void Font::GlyphTexture::apply(osg::State& state) const // so to get round this copy all glyphs into a temporary image and // then subload the whole lot in one go. +#ifdef OSG_FONT_USE_LUMINANCE_ALPHA int tsize = 2 * getTextureHeight() * getTextureWidth(); unsigned char *local_data = new unsigned char[tsize]; memset( local_data, 0L, tsize); @@ -555,6 +571,49 @@ void Font::GlyphTexture::apply(osg::State& state) const GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, local_data ); delete [] local_data; +#else + int tsize = getTextureHeight() * getTextureWidth(); + unsigned char *local_data = new unsigned char[tsize]; + memset( local_data, 0L, tsize); + + for(GlyphRefList::const_iterator itr=_glyphs.begin(); + itr!=_glyphs.end(); + ++itr) + { + //(*itr)->subload(); + + // Rather than subloading to graphics, we'll write the values + // of the glyphs into some intermediate data and subload the + // whole thing at the end + for( int t = 0; t < (*itr)->t(); t++ ) + { + for( int s = 0; s < (*itr)->s(); s++ ) + { + int sindex = (t*(*itr)->s()+s); + int dindex = + ((((*itr)->getTexturePositionY()+t) * getTextureWidth()) + + ((*itr)->getTexturePositionX()+s)); + + const unsigned char *sptr = &(*itr)->data()[sindex]; + unsigned char *dptr = &local_data[dindex]; + + (*dptr) = (*sptr); + } + } + } + + // clear the list since we have now subloaded them. + glyphsWereSubloading.clear(); + + // Subload the image once + glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, + getTextureWidth(), + getTextureHeight(), + GL_ALPHA, GL_UNSIGNED_BYTE, local_data ); + + delete [] local_data; +#endif + } } else