Moved osgText across to create GL_ALPHA textures instead of GL_LUMINANCE_ALPHA
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
#include <osg/Texture2D>
|
||||
#include <osg/StateSet>
|
||||
#include <osg/buffered_value>
|
||||
#include <osg/TexEnv>
|
||||
|
||||
#include <osgText/Export>
|
||||
|
||||
@@ -137,6 +138,8 @@ protected:
|
||||
osg::Texture::FilterMode _minFilterHint;
|
||||
osg::Texture::FilterMode _magFilterHint;
|
||||
|
||||
osg::ref_ptr<osg::TexEnv > _texEnv;
|
||||
|
||||
osg::ref_ptr<FontImplementation> _implementation;
|
||||
|
||||
|
||||
|
||||
@@ -79,6 +79,10 @@ osgText::Font::Glyph* FreeTypeFont::getGlyph(unsigned int charcode)
|
||||
|
||||
osg::ref_ptr<osgText::Font::Glyph> glyph = new osgText::Font::Glyph;
|
||||
|
||||
|
||||
|
||||
//#define USE_LUMINANCE_ALPHA
|
||||
#ifdef USE_LUMINANCE_ALPHA
|
||||
unsigned int dataSize = width*height*2;
|
||||
unsigned char* data = new unsigned char[dataSize];
|
||||
|
||||
@@ -92,7 +96,7 @@ osgText::Font::Glyph* FreeTypeFont::getGlyph(unsigned int charcode)
|
||||
data,
|
||||
osg::Image::USE_NEW_DELETE,
|
||||
1);
|
||||
|
||||
|
||||
// skip the top margin
|
||||
data += (margin*width)*2;
|
||||
|
||||
@@ -109,7 +113,41 @@ osgText::Font::Glyph* FreeTypeFont::getGlyph(unsigned int charcode)
|
||||
}
|
||||
data+=2*margin; // skip the right margin.
|
||||
}
|
||||
#else
|
||||
unsigned int dataSize = width*height;
|
||||
unsigned char* data = new unsigned char[dataSize];
|
||||
|
||||
|
||||
// clear the image to zeros.
|
||||
for(unsigned char* p=data;p<data+dataSize;) { *p++ = 0; }
|
||||
|
||||
glyph->setImage(width,height,1,
|
||||
GL_ALPHA,
|
||||
GL_ALPHA,GL_UNSIGNED_BYTE,
|
||||
data,
|
||||
osg::Image::USE_NEW_DELETE,
|
||||
1);
|
||||
|
||||
glyph->setInternalTextureFormat(GL_ALPHA);
|
||||
|
||||
// skip the top margin
|
||||
data += (margin*width);
|
||||
|
||||
// copy image across to osgText::Glyph image.
|
||||
for(int r=sourceHeight-1;r>=0;--r)
|
||||
{
|
||||
data+=margin; // skip the left margin
|
||||
|
||||
unsigned char* ptr = buffer+r*pitch;
|
||||
for(unsigned int c=0;c<sourceWidth;++c,++ptr)
|
||||
{
|
||||
(*data++)=*ptr;
|
||||
}
|
||||
data+=margin; // skip the right margin.
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
FT_Glyph_Metrics* metrics = &(glyphslot->metrics);
|
||||
|
||||
glyph->setHorizontalBearing(osg::Vec2((float)metrics->horiBearingX/64.0f,(float)(metrics->horiBearingY-metrics->height)/64.0f)); // bottom left.
|
||||
|
||||
@@ -195,10 +195,10 @@ void DefaultFont::constructGlyphs()
|
||||
unsigned int sourceWidth = 8;
|
||||
unsigned int sourceHeight = 12;
|
||||
|
||||
//#define USE_LUMINANCE_ALPHA
|
||||
#ifdef USE_LUMINANCE_ALPHA
|
||||
_width = sourceWidth+2*_margin;
|
||||
_height = sourceHeight+2*_margin;
|
||||
|
||||
|
||||
|
||||
// populate the glyph mp
|
||||
for(unsigned int i=32;i<127;i++)
|
||||
@@ -229,22 +229,6 @@ void DefaultFont::constructGlyphs()
|
||||
for(unsigned int row=0;row<sourceHeight;++row,++ptr)
|
||||
{
|
||||
data+=2*_margin; // skip the left margin
|
||||
// (*data++)=((*ptr)&128)?value_on:value_off;
|
||||
// (*data++)=((*ptr)&128)?value_on:value_off;
|
||||
// (*data++)=((*ptr)&64)?value_on:value_off;
|
||||
// (*data++)=((*ptr)&64)?value_on:value_off;
|
||||
// (*data++)=((*ptr)&32)?value_on:value_off;
|
||||
// (*data++)=((*ptr)&32)?value_on:value_off;
|
||||
// (*data++)=((*ptr)&16)?value_on:value_off;
|
||||
// (*data++)=((*ptr)&16)?value_on:value_off;
|
||||
// (*data++)=((*ptr)&8)?value_on:value_off;
|
||||
// (*data++)=((*ptr)&8)?value_on:value_off;
|
||||
// (*data++)=((*ptr)&4)?value_on:value_off;
|
||||
// (*data++)=((*ptr)&4)?value_on:value_off;
|
||||
// (*data++)=((*ptr)&2)?value_on:value_off;
|
||||
// (*data++)=((*ptr)&2)?value_on:value_off;
|
||||
// (*data++)=((*ptr)&1)?value_on:value_off;
|
||||
// (*data++)=((*ptr)&1)?value_on:value_off;
|
||||
(*data++)=255;
|
||||
(*data++)=((*ptr)&128)?value_on:value_off;
|
||||
(*data++)=255;
|
||||
@@ -263,7 +247,52 @@ void DefaultFont::constructGlyphs()
|
||||
(*data++)=((*ptr)&1)?value_on:value_off;
|
||||
data+=2*_margin; // skip the right margin.
|
||||
}
|
||||
#else
|
||||
_width = sourceWidth+2*_margin;
|
||||
_height = sourceHeight+2*_margin;
|
||||
|
||||
// populate the glyph mp
|
||||
for(unsigned int i=32;i<127;i++)
|
||||
{
|
||||
osg::ref_ptr<Glyph> glyph = new Glyph;
|
||||
|
||||
unsigned int dataSize = _width*_height;
|
||||
unsigned char* data = new unsigned char[dataSize];
|
||||
|
||||
// clear the image to zeros.
|
||||
for(unsigned char* p=data;p<data+dataSize;) { *p++ = 0; }
|
||||
|
||||
glyph->setImage(_width,_height,1,
|
||||
GL_ALPHA,
|
||||
GL_ALPHA,GL_UNSIGNED_BYTE,
|
||||
data,
|
||||
osg::Image::USE_NEW_DELETE,
|
||||
1);
|
||||
|
||||
glyph->setInternalTextureFormat(GL_ALPHA);
|
||||
|
||||
// now populate data arry by converting bitmap into a luminance_alpha map.
|
||||
unsigned char* ptr = rasters[i-32];
|
||||
unsigned char value_on = 255;
|
||||
unsigned char value_off = 0;
|
||||
|
||||
// skip the top margin
|
||||
data += (_margin*_width);
|
||||
|
||||
for(unsigned int row=0;row<sourceHeight;++row,++ptr)
|
||||
{
|
||||
data+=_margin; // skip the left margin
|
||||
(*data++)=((*ptr)&128)?value_on:value_off;
|
||||
(*data++)=((*ptr)&64)?value_on:value_off;
|
||||
(*data++)=((*ptr)&32)?value_on:value_off;
|
||||
(*data++)=((*ptr)&16)?value_on:value_off;
|
||||
(*data++)=((*ptr)&8)?value_on:value_off;
|
||||
(*data++)=((*ptr)&4)?value_on:value_off;
|
||||
(*data++)=((*ptr)&2)?value_on:value_off;
|
||||
(*data++)=((*ptr)&1)?value_on:value_off;
|
||||
data+=_margin; // skip the right margin.
|
||||
}
|
||||
#endif
|
||||
|
||||
glyph->setHorizontalBearing(osg::Vec2(0.0f,0.0f)); // bottom left.
|
||||
glyph->setHorizontalAdvance((float)_width);
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
|
||||
#include <osg/State>
|
||||
#include <osg/Notify>
|
||||
#include <osg/TexEnv>
|
||||
|
||||
#include <osgDB/ReadFile>
|
||||
#include <osgDB/FileUtils>
|
||||
#include <osg/GLU>
|
||||
@@ -87,6 +89,7 @@ Font::Font(FontImplementation* implementation):
|
||||
_magFilterHint(osg::Texture::LINEAR)
|
||||
{
|
||||
setImplementation(implementation);
|
||||
_texEnv = new osg::TexEnv(osg::TexEnv::BLEND);
|
||||
}
|
||||
|
||||
Font::~Font()
|
||||
@@ -259,6 +262,7 @@ void Font::addGlyph(unsigned int width, unsigned int height, unsigned int charco
|
||||
glyphTexture->setStateSet(stateset);
|
||||
stateset->setMode(GL_BLEND,osg::StateAttribute::ON);
|
||||
stateset->setTextureAttributeAndModes(0,glyphTexture,osg::StateAttribute::ON);
|
||||
if (_texEnv.valid()) stateset->setTextureAttribute(0,_texEnv.get());
|
||||
stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
|
||||
|
||||
if (!glyphTexture->getSpaceForGlyph(glyph,posX,posY))
|
||||
|
||||
Reference in New Issue
Block a user