Merged the Text::GlyphQuads cooordinate arrays
This commit is contained in:
parent
e5685dfca5
commit
138af70bd8
@ -13,10 +13,30 @@ void textInfo(osgText::Text* text)
|
|||||||
|
|
||||||
const osgText::Text::TextureGlyphQuadMap::const_iterator tgqmi = tgqm.begin();
|
const osgText::Text::TextureGlyphQuadMap::const_iterator tgqmi = tgqm.begin();
|
||||||
|
|
||||||
const osgText::Text::GlyphQuads& gq = tgqmi->second;
|
|
||||||
|
|
||||||
osgText::String& s = text->getText();
|
osgText::String& s = text->getText();
|
||||||
|
|
||||||
|
#ifdef NEW_APPROACH
|
||||||
|
for(unsigned int i = 0; i < s.size(); i++)
|
||||||
|
{
|
||||||
|
osg::Vec2 ul; text->getCoord(0 + (i * 4), ul); // upperLeft
|
||||||
|
osg::Vec2 ll; text->getCoord(1 + (i * 4), ll); // lowerLeft
|
||||||
|
osg::Vec2 lr; text->getCoord(2 + (i * 4), lr); // lowerRight
|
||||||
|
osg::Vec2 ur; text->getCoord(3 + (i * 4), ur); // upperRight
|
||||||
|
|
||||||
|
osg::notify(osg::NOTICE)
|
||||||
|
<< "'" << static_cast<char>(s[i]) << "':"
|
||||||
|
<< " width(" << lr.x() - ll.x() << ")"
|
||||||
|
<< " height(" << ul.y() - ll.y() << ")" << std::endl << "\t"
|
||||||
|
<< "ul(" << ul << "), "
|
||||||
|
<< "ll(" << ll << "), "
|
||||||
|
<< "lr(" << lr << "), "
|
||||||
|
<< "ur(" << ur << ")"
|
||||||
|
<< std::endl
|
||||||
|
;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
const osgText::Text::GlyphQuads& gq = tgqmi->second;
|
||||||
for(unsigned int i = 0; i < s.size(); i++)
|
for(unsigned int i = 0; i < s.size(); i++)
|
||||||
{
|
{
|
||||||
osg::Vec2 ul; gq.getCoord(0 + (i * 4), ul); // upperLeft
|
osg::Vec2 ul; gq.getCoord(0 + (i * 4), ul); // upperLeft
|
||||||
@ -35,6 +55,7 @@ void textInfo(osgText::Text* text)
|
|||||||
<< std::endl
|
<< std::endl
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
osg::Camera* createOrthoCamera(double width, double height)
|
osg::Camera* createOrthoCamera(double width, double height)
|
||||||
|
@ -295,20 +295,42 @@ public:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
typedef osg::ref_ptr<osg::Vec3Array> Coords;
|
||||||
|
typedef osg::ref_ptr<osg::Vec2Array> TexCoords;
|
||||||
|
typedef osg::ref_ptr<osg::Vec4Array> ColorCoords;
|
||||||
|
|
||||||
|
#ifdef NEW_APPROACH
|
||||||
|
Coords _coords;
|
||||||
|
ColorCoords _colorCoords;
|
||||||
|
TexCoords _texcoords;
|
||||||
|
|
||||||
|
unsigned int addCoord(const osg::Vec2& c) { unsigned int s = _coords->size(); _coords->push_back(osg::Vec3(c.x(), c.y(), 0.0f)); return s; }
|
||||||
|
unsigned int addCoord(const osg::Vec3& c) { unsigned int s = _coords->size(); _coords->push_back(c); return s; }
|
||||||
|
|
||||||
|
void getCoord(unsigned int i, osg::Vec2& c) const { c.set((*_coords)[i].x(), (*_coords)[i].y()); }
|
||||||
|
void getCoord(unsigned int i, osg::Vec3& c) const { c = (*_coords)[i]; }
|
||||||
|
|
||||||
|
Coords& getCoords() { return _coords; }
|
||||||
|
const Coords& getCoords() const { return _coords; }
|
||||||
|
|
||||||
|
void addTexCoord(const osg::Vec2& tc) { _texcoords->push_back(tc); }
|
||||||
|
#endif
|
||||||
// internal structures, variable and methods used for rendering of characters.
|
// internal structures, variable and methods used for rendering of characters.
|
||||||
struct OSGTEXT_EXPORT GlyphQuads
|
struct OSGTEXT_EXPORT GlyphQuads
|
||||||
{
|
{
|
||||||
typedef std::vector<Glyph*> Glyphs;
|
typedef std::vector<Glyph*> Glyphs;
|
||||||
typedef std::vector<unsigned int> LineNumbers;
|
typedef std::vector<unsigned int> LineNumbers;
|
||||||
typedef osg::ref_ptr<osg::Vec3Array> Coords;
|
|
||||||
typedef osg::ref_ptr<osg::Vec2Array> TexCoords;
|
|
||||||
typedef osg::ref_ptr<osg::Vec4Array> ColorCoords;
|
|
||||||
typedef std::vector< osg::ref_ptr<osg::DrawElementsUShort> > Primitives;
|
typedef std::vector< osg::ref_ptr<osg::DrawElementsUShort> > Primitives;
|
||||||
|
|
||||||
Glyphs _glyphs;
|
Glyphs _glyphs;
|
||||||
|
#ifndef NEW_APPROACH
|
||||||
Coords _coords;
|
Coords _coords;
|
||||||
ColorCoords _colorCoords;
|
ColorCoords _colorCoords;
|
||||||
TexCoords _texcoords;
|
TexCoords _texcoords;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
unsigned int _coordBase;
|
||||||
|
|
||||||
|
|
||||||
Primitives _primitives;
|
Primitives _primitives;
|
||||||
|
|
||||||
@ -324,8 +346,9 @@ public:
|
|||||||
Glyphs& getGlyphs() { return _glyphs; }
|
Glyphs& getGlyphs() { return _glyphs; }
|
||||||
const Glyphs& getGlyphs() const { return _glyphs; }
|
const Glyphs& getGlyphs() const { return _glyphs; }
|
||||||
|
|
||||||
void addCoord(const osg::Vec2& c) { _coords->push_back(osg::Vec3(c.x(), c.y(), 0.0f)); }
|
#ifndef NEW_APPROACH
|
||||||
void addCoord(const osg::Vec3& c) { _coords->push_back(c); }
|
unsigned int addCoord(const osg::Vec2& c) { unsigned int s = _coords->size(); _coords->push_back(osg::Vec3(c.x(), c.y(), 0.0f)); return s; }
|
||||||
|
unsigned int addCoord(const osg::Vec3& c) { unsigned int s = _coords->size(); _coords->push_back(c); return s; }
|
||||||
|
|
||||||
void getCoord(unsigned int i, osg::Vec2& c) const { c.set((*_coords)[i].x(), (*_coords)[i].y()); }
|
void getCoord(unsigned int i, osg::Vec2& c) const { c.set((*_coords)[i].x(), (*_coords)[i].y()); }
|
||||||
void getCoord(unsigned int i, osg::Vec3& c) const { c = (*_coords)[i]; }
|
void getCoord(unsigned int i, osg::Vec3& c) const { c = (*_coords)[i]; }
|
||||||
@ -334,6 +357,7 @@ public:
|
|||||||
const Coords& getCoords() const { return _coords; }
|
const Coords& getCoords() const { return _coords; }
|
||||||
|
|
||||||
void addTexCoord(const osg::Vec2& tc) { _texcoords->push_back(tc); }
|
void addTexCoord(const osg::Vec2& tc) { _texcoords->push_back(tc); }
|
||||||
|
#endif
|
||||||
|
|
||||||
/** Resize any per context GLObject buffers to specified size. */
|
/** Resize any per context GLObject buffers to specified size. */
|
||||||
void resizeGLObjectBuffers(unsigned int maxSize);
|
void resizeGLObjectBuffers(unsigned int maxSize);
|
||||||
|
@ -230,17 +230,49 @@ void Text::addGlyphQuad(Glyph* glyph, const osg::Vec2& minc, const osg::Vec2& ma
|
|||||||
GlyphQuads& glyphquad = _textureGlyphQuadMap[glyph->getTexture()];
|
GlyphQuads& glyphquad = _textureGlyphQuadMap[glyph->getTexture()];
|
||||||
|
|
||||||
glyphquad._glyphs.push_back(glyph);
|
glyphquad._glyphs.push_back(glyph);
|
||||||
|
osg::DrawElementsUShort* primitives = glyphquad._primitives[0].get();
|
||||||
|
|
||||||
glyphquad.addCoord(osg::Vec2(minc.x(), maxc.y()));
|
#ifdef NEW_APPROACH
|
||||||
glyphquad.addCoord(osg::Vec2(minc.x(), minc.y()));
|
|
||||||
glyphquad.addCoord(osg::Vec2(maxc.x(), minc.y()));
|
unsigned int lt = addCoord(osg::Vec2(minc.x(), maxc.y()));
|
||||||
glyphquad.addCoord(osg::Vec2(maxc.x(), maxc.y()));
|
unsigned int lb = addCoord(osg::Vec2(minc.x(), minc.y()));
|
||||||
|
unsigned int rb = addCoord(osg::Vec2(maxc.x(), minc.y()));
|
||||||
|
unsigned int rt = addCoord(osg::Vec2(maxc.x(), maxc.y()));
|
||||||
|
|
||||||
|
// set up the tex coords of the quad
|
||||||
|
addTexCoord(osg::Vec2(mintc.x(), maxtc.y()));
|
||||||
|
addTexCoord(osg::Vec2(mintc.x(), mintc.y()));
|
||||||
|
addTexCoord(osg::Vec2(maxtc.x(), mintc.y()));
|
||||||
|
addTexCoord(osg::Vec2(maxtc.x(), maxtc.y()));
|
||||||
|
|
||||||
|
primitives->push_back(lt);
|
||||||
|
primitives->push_back(lb);
|
||||||
|
primitives->push_back(rb);
|
||||||
|
|
||||||
|
primitives->push_back(lt);
|
||||||
|
primitives->push_back(rb);
|
||||||
|
primitives->push_back(rt);
|
||||||
|
|
||||||
|
#else
|
||||||
|
unsigned int lt = glyphquad.addCoord(osg::Vec2(minc.x(), maxc.y()));
|
||||||
|
unsigned int lb = glyphquad.addCoord(osg::Vec2(minc.x(), minc.y()));
|
||||||
|
unsigned int rb = glyphquad.addCoord(osg::Vec2(maxc.x(), minc.y()));
|
||||||
|
unsigned int rt = glyphquad.addCoord(osg::Vec2(maxc.x(), maxc.y()));
|
||||||
|
|
||||||
// set up the tex coords of the quad
|
// set up the tex coords of the quad
|
||||||
glyphquad.addTexCoord(osg::Vec2(mintc.x(), maxtc.y()));
|
glyphquad.addTexCoord(osg::Vec2(mintc.x(), maxtc.y()));
|
||||||
glyphquad.addTexCoord(osg::Vec2(mintc.x(), mintc.y()));
|
glyphquad.addTexCoord(osg::Vec2(mintc.x(), mintc.y()));
|
||||||
glyphquad.addTexCoord(osg::Vec2(maxtc.x(), mintc.y()));
|
glyphquad.addTexCoord(osg::Vec2(maxtc.x(), mintc.y()));
|
||||||
glyphquad.addTexCoord(osg::Vec2(maxtc.x(), maxtc.y()));
|
glyphquad.addTexCoord(osg::Vec2(maxtc.x(), maxtc.y()));
|
||||||
|
|
||||||
|
primitives->push_back(lt);
|
||||||
|
primitives->push_back(lb);
|
||||||
|
primitives->push_back(rb);
|
||||||
|
|
||||||
|
primitives->push_back(lt);
|
||||||
|
primitives->push_back(rb);
|
||||||
|
primitives->push_back(rt);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void Text::computeGlyphRepresentation()
|
void Text::computeGlyphRepresentation()
|
||||||
@ -248,6 +280,13 @@ void Text::computeGlyphRepresentation()
|
|||||||
Font* activefont = getActiveFont();
|
Font* activefont = getActiveFont();
|
||||||
if (!activefont) return;
|
if (!activefont) return;
|
||||||
|
|
||||||
|
#ifdef NEW_APPROACH
|
||||||
|
_coords = new osg::Vec3Array(osg::Array::BIND_PER_VERTEX);
|
||||||
|
_colorCoords = new osg::Vec4Array(osg::Array::BIND_PER_VERTEX);
|
||||||
|
_texcoords = new osg::Vec2Array(osg::Array::BIND_PER_VERTEX);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
_textureGlyphQuadMap.clear();
|
_textureGlyphQuadMap.clear();
|
||||||
_lineCount = 0;
|
_lineCount = 0;
|
||||||
|
|
||||||
@ -554,6 +593,18 @@ bool Text::computeAverageGlyphWidthAndHeight(float& avg_width, float& avg_height
|
|||||||
int counter = 0;
|
int counter = 0;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
bool is_valid_size = true;
|
bool is_valid_size = true;
|
||||||
|
|
||||||
|
#ifdef NEW_APPROACH
|
||||||
|
for (i = 0; i < _coords->size(); i += 4)
|
||||||
|
{
|
||||||
|
width = (*_coords)[i + 2].x() - (*_coords)[i].x();
|
||||||
|
height = (*_coords)[i].y() - (*_coords)[i + 1].y();
|
||||||
|
|
||||||
|
running_width += width;
|
||||||
|
running_height += height;
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
#else
|
||||||
// This section is going to try to compute the average width and height
|
// This section is going to try to compute the average width and height
|
||||||
// for a character among the text. The reason I shift by an
|
// for a character among the text. The reason I shift by an
|
||||||
// average amount per-character instead of shifting each character
|
// average amount per-character instead of shifting each character
|
||||||
@ -568,7 +619,7 @@ bool Text::computeAverageGlyphWidthAndHeight(float& avg_width, float& avg_height
|
|||||||
++const_titr)
|
++const_titr)
|
||||||
{
|
{
|
||||||
const GlyphQuads& glyphquad = const_titr->second;
|
const GlyphQuads& glyphquad = const_titr->second;
|
||||||
const GlyphQuads::Coords& coords = glyphquad._coords;
|
const Coords& coords = glyphquad._coords;
|
||||||
for (i = 0; i < coords->size(); i += 4)
|
for (i = 0; i < coords->size(); i += 4)
|
||||||
{
|
{
|
||||||
width = (*coords)[i + 2].x() - (*coords)[i].x();
|
width = (*coords)[i + 2].x() - (*coords)[i].x();
|
||||||
@ -579,6 +630,7 @@ bool Text::computeAverageGlyphWidthAndHeight(float& avg_width, float& avg_height
|
|||||||
counter++;
|
counter++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
if(0 == counter)
|
if(0 == counter)
|
||||||
{
|
{
|
||||||
is_valid_size = false;
|
is_valid_size = false;
|
||||||
@ -620,106 +672,125 @@ void Text::computeBackdropPositions()
|
|||||||
|
|
||||||
if (!is_valid_size) return;
|
if (!is_valid_size) return;
|
||||||
|
|
||||||
// now apply matrix to the glyphs.
|
unsigned int backdrop_index;
|
||||||
for(TextureGlyphQuadMap::iterator titr=_textureGlyphQuadMap.begin();
|
unsigned int max_backdrop_index;
|
||||||
titr!=_textureGlyphQuadMap.end();
|
if(_backdropType == OUTLINE)
|
||||||
++titr)
|
|
||||||
{
|
{
|
||||||
GlyphQuads& glyphquad = titr->second;
|
// For outline, we want to draw the in every direction
|
||||||
unsigned int numCoords = glyphquad._glyphs.size()*4;
|
backdrop_index = 0;
|
||||||
|
max_backdrop_index = 8;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Yes, this may seem a little strange,
|
||||||
|
// but since the code is using references,
|
||||||
|
// I would have to duplicate the following code twice
|
||||||
|
// for each part of the if/else because I can't
|
||||||
|
// declare a reference without setting it immediately
|
||||||
|
// and it wouldn't survive the scope.
|
||||||
|
// So it happens that the _backdropType value matches
|
||||||
|
// the index in the array I want to store the coordinates
|
||||||
|
// in. So I'll just setup the for-loop so it only does
|
||||||
|
// the one direction I'm interested in.
|
||||||
|
backdrop_index = _backdropType;
|
||||||
|
max_backdrop_index = _backdropType+1;
|
||||||
|
}
|
||||||
|
|
||||||
GlyphQuads::Coords& coords = glyphquad._coords;
|
for( ; backdrop_index < max_backdrop_index; backdrop_index++)
|
||||||
GlyphQuads::TexCoords& texcoords = glyphquad._texcoords;
|
{
|
||||||
|
float horizontal_shift_direction;
|
||||||
|
float vertical_shift_direction;
|
||||||
|
switch(backdrop_index)
|
||||||
|
{
|
||||||
|
case DROP_SHADOW_BOTTOM_RIGHT:
|
||||||
|
{
|
||||||
|
horizontal_shift_direction = 1.0f;
|
||||||
|
vertical_shift_direction = -1.0f;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case DROP_SHADOW_CENTER_RIGHT:
|
||||||
|
{
|
||||||
|
horizontal_shift_direction = 1.0f;
|
||||||
|
vertical_shift_direction = 0.0f;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case DROP_SHADOW_TOP_RIGHT:
|
||||||
|
{
|
||||||
|
horizontal_shift_direction = 1.0f;
|
||||||
|
vertical_shift_direction = 1.0f;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case DROP_SHADOW_BOTTOM_CENTER:
|
||||||
|
{
|
||||||
|
horizontal_shift_direction = 0.0f;
|
||||||
|
vertical_shift_direction = -1.0f;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case DROP_SHADOW_TOP_CENTER:
|
||||||
|
{
|
||||||
|
horizontal_shift_direction = 0.0f;
|
||||||
|
vertical_shift_direction = 1.0f;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case DROP_SHADOW_BOTTOM_LEFT:
|
||||||
|
{
|
||||||
|
horizontal_shift_direction = -1.0f;
|
||||||
|
vertical_shift_direction = -1.0f;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case DROP_SHADOW_CENTER_LEFT:
|
||||||
|
{
|
||||||
|
horizontal_shift_direction = -1.0f;
|
||||||
|
vertical_shift_direction = 0.0f;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case DROP_SHADOW_TOP_LEFT:
|
||||||
|
{
|
||||||
|
horizontal_shift_direction = -1.0f;
|
||||||
|
vertical_shift_direction = 1.0f;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: // error
|
||||||
|
{
|
||||||
|
horizontal_shift_direction = 1.0f;
|
||||||
|
vertical_shift_direction = -1.0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
unsigned int backdrop_index;
|
// now apply matrix to the glyphs.
|
||||||
unsigned int max_backdrop_index;
|
for(TextureGlyphQuadMap::iterator titr=_textureGlyphQuadMap.begin();
|
||||||
if(_backdropType == OUTLINE)
|
titr!=_textureGlyphQuadMap.end();
|
||||||
|
++titr)
|
||||||
{
|
{
|
||||||
// For outline, we want to draw the in every direction
|
GlyphQuads& glyphquad = titr->second;
|
||||||
backdrop_index = 0;
|
osg::DrawElementsUShort* src_primitives = glyphquad._primitives[0].get();
|
||||||
max_backdrop_index = 8;
|
osg::DrawElementsUShort* dst_primitives = new osg::DrawElementsUShort(GL_TRIANGLES);
|
||||||
}
|
glyphquad._primitives.push_back(dst_primitives);
|
||||||
else
|
|
||||||
{
|
unsigned int numCoords = src_primitives->size();
|
||||||
// Yes, this may seem a little strange,
|
|
||||||
// but since the code is using references,
|
#ifdef NEW_APPROACH
|
||||||
// I would have to duplicate the following code twice
|
Coords& src_coords = _coords;
|
||||||
// for each part of the if/else because I can't
|
TexCoords& src_texcoords = _texcoords;
|
||||||
// declare a reference without setting it immediately
|
|
||||||
// and it wouldn't survive the scope.
|
Coords& dst_coords = _coords;
|
||||||
// So it happens that the _backdropType value matches
|
TexCoords& dst_texcoords = _texcoords;
|
||||||
// the index in the array I want to store the coordinates
|
#else
|
||||||
// in. So I'll just setup the for-loop so it only does
|
Coords& src_coords = glyphquad._coords;
|
||||||
// the one direction I'm interested in.
|
TexCoords& src_texcoords = glyphquad._texcoords;
|
||||||
backdrop_index = _backdropType;
|
|
||||||
max_backdrop_index = _backdropType+1;
|
Coords& dst_coords = glyphquad._coords;
|
||||||
}
|
TexCoords& dst_texcoords = glyphquad._texcoords;
|
||||||
for( ; backdrop_index < max_backdrop_index; backdrop_index++)
|
#endif
|
||||||
{
|
|
||||||
GlyphQuads::Coords& transformedCoords = glyphquad._coords;
|
|
||||||
for(i=0;i<numCoords;++i)
|
for(i=0;i<numCoords;++i)
|
||||||
{
|
{
|
||||||
float horizontal_shift_direction;
|
unsigned int si = (*src_primitives)[i];
|
||||||
float vertical_shift_direction;
|
osg::Vec3 v(horizontal_shift_direction * _backdropHorizontalOffset * avg_width + (*src_coords)[si].x(), vertical_shift_direction * _backdropVerticalOffset * avg_height + (*src_coords)[si].y(), 0.0f);
|
||||||
switch(backdrop_index)
|
unsigned int di = dst_coords->size();
|
||||||
{
|
(*dst_primitives).push_back(di);
|
||||||
case DROP_SHADOW_BOTTOM_RIGHT:
|
(*dst_coords).push_back(v);
|
||||||
{
|
(*dst_texcoords).push_back((*src_texcoords)[si]);
|
||||||
horizontal_shift_direction = 1.0f;
|
|
||||||
vertical_shift_direction = -1.0f;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case DROP_SHADOW_CENTER_RIGHT:
|
|
||||||
{
|
|
||||||
horizontal_shift_direction = 1.0f;
|
|
||||||
vertical_shift_direction = 0.0f;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case DROP_SHADOW_TOP_RIGHT:
|
|
||||||
{
|
|
||||||
horizontal_shift_direction = 1.0f;
|
|
||||||
vertical_shift_direction = 1.0f;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case DROP_SHADOW_BOTTOM_CENTER:
|
|
||||||
{
|
|
||||||
horizontal_shift_direction = 0.0f;
|
|
||||||
vertical_shift_direction = -1.0f;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case DROP_SHADOW_TOP_CENTER:
|
|
||||||
{
|
|
||||||
horizontal_shift_direction = 0.0f;
|
|
||||||
vertical_shift_direction = 1.0f;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case DROP_SHADOW_BOTTOM_LEFT:
|
|
||||||
{
|
|
||||||
horizontal_shift_direction = -1.0f;
|
|
||||||
vertical_shift_direction = -1.0f;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case DROP_SHADOW_CENTER_LEFT:
|
|
||||||
{
|
|
||||||
horizontal_shift_direction = -1.0f;
|
|
||||||
vertical_shift_direction = 0.0f;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case DROP_SHADOW_TOP_LEFT:
|
|
||||||
{
|
|
||||||
horizontal_shift_direction = -1.0f;
|
|
||||||
vertical_shift_direction = 1.0f;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default: // error
|
|
||||||
{
|
|
||||||
horizontal_shift_direction = 1.0f;
|
|
||||||
vertical_shift_direction = -1.0f;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
osg::Vec3 v(horizontal_shift_direction * _backdropHorizontalOffset * avg_width + (*coords)[i].x(), vertical_shift_direction * _backdropVerticalOffset * avg_height + (*coords)[i].y(), 0.0f);
|
|
||||||
(*transformedCoords).push_back(v);
|
|
||||||
(*texcoords).push_back((*texcoords)[i]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -912,13 +983,16 @@ void Text::computeColorGradientsOverall()
|
|||||||
|
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
|
#ifndef NEW_APPROACH
|
||||||
for(TextureGlyphQuadMap::const_iterator const_titr=_textureGlyphQuadMap.begin();
|
for(TextureGlyphQuadMap::const_iterator const_titr=_textureGlyphQuadMap.begin();
|
||||||
const_titr!=_textureGlyphQuadMap.end();
|
const_titr!=_textureGlyphQuadMap.end();
|
||||||
++const_titr)
|
++const_titr)
|
||||||
{
|
{
|
||||||
const GlyphQuads& glyphquad = const_titr->second;
|
const GlyphQuads& glyphquad = const_titr->second;
|
||||||
const GlyphQuads::Coords& coords = glyphquad._coords;
|
const Coords& coords = glyphquad._coords;
|
||||||
|
#else
|
||||||
|
const Coords& coords = _coords;
|
||||||
|
#endif
|
||||||
for(i=0;i<coords->size();++i)
|
for(i=0;i<coords->size();++i)
|
||||||
{
|
{
|
||||||
// Min and Max are needed for color gradients
|
// Min and Max are needed for color gradients
|
||||||
@ -940,15 +1014,21 @@ void Text::computeColorGradientsOverall()
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#ifndef NEW_APPROACH
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef NEW_APPROACH
|
||||||
for(TextureGlyphQuadMap::iterator titr=_textureGlyphQuadMap.begin();
|
for(TextureGlyphQuadMap::iterator titr=_textureGlyphQuadMap.begin();
|
||||||
titr!=_textureGlyphQuadMap.end();
|
titr!=_textureGlyphQuadMap.end();
|
||||||
++titr)
|
++titr)
|
||||||
{
|
{
|
||||||
GlyphQuads& glyphquad = titr->second;
|
GlyphQuads& glyphquad = titr->second;
|
||||||
GlyphQuads::Coords& coords = glyphquad._coords;
|
const Coords& coords = glyphquad._coords;
|
||||||
GlyphQuads::ColorCoords& colorCoords = glyphquad._colorCoords;
|
const ColorCoords& colorCoords = glyphquad._colorCoords;
|
||||||
|
#else
|
||||||
|
const ColorCoords& colorCoords = _colorCoords;
|
||||||
|
#endif
|
||||||
|
|
||||||
unsigned int numCoords = coords->size();
|
unsigned int numCoords = coords->size();
|
||||||
if (numCoords!=colorCoords->size())
|
if (numCoords!=colorCoords->size())
|
||||||
@ -1012,19 +1092,25 @@ void Text::computeColorGradientsOverall()
|
|||||||
|
|
||||||
(*colorCoords)[i] = osg::Vec4(red,green,blue,alpha);
|
(*colorCoords)[i] = osg::Vec4(red,green,blue,alpha);
|
||||||
}
|
}
|
||||||
|
#ifndef NEW_APPROACH
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void Text::computeColorGradientsPerCharacter()
|
void Text::computeColorGradientsPerCharacter()
|
||||||
{
|
{
|
||||||
|
#ifndef NEW_APPROACH
|
||||||
for(TextureGlyphQuadMap::iterator titr=_textureGlyphQuadMap.begin();
|
for(TextureGlyphQuadMap::iterator titr=_textureGlyphQuadMap.begin();
|
||||||
titr!=_textureGlyphQuadMap.end();
|
titr!=_textureGlyphQuadMap.end();
|
||||||
++titr)
|
++titr)
|
||||||
{
|
{
|
||||||
GlyphQuads& glyphquad = titr->second;
|
GlyphQuads& glyphquad = titr->second;
|
||||||
GlyphQuads::Coords& coords = glyphquad._coords;
|
Coords& coords = glyphquad._coords;
|
||||||
GlyphQuads::ColorCoords& colorCoords = glyphquad._colorCoords;
|
ColorCoords& colorCoords = glyphquad._colorCoords;
|
||||||
|
#else
|
||||||
|
Coords& coords = _coords;
|
||||||
|
ColorCoords& colorCoords = _colorCoords;
|
||||||
|
#endif
|
||||||
unsigned int numCoords = coords->size();
|
unsigned int numCoords = coords->size();
|
||||||
if (numCoords!=colorCoords->size())
|
if (numCoords!=colorCoords->size())
|
||||||
{
|
{
|
||||||
@ -1061,7 +1147,9 @@ void Text::computeColorGradientsPerCharacter()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#ifndef NEW_APPROACH
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void Text::drawImplementation(osg::RenderInfo& renderInfo) const
|
void Text::drawImplementation(osg::RenderInfo& renderInfo) const
|
||||||
@ -1113,6 +1201,7 @@ void Text::drawImplementation(osg::State& state, const osg::Vec4& colorMultiplie
|
|||||||
osg::State::ApplyModeProxy applyMode(state, GL_LIGHTING, false);
|
osg::State::ApplyModeProxy applyMode(state, GL_LIGHTING, false);
|
||||||
osg::State::ApplyTextureModeProxy applyTextureMode(state, 0, GL_TEXTURE_2D, false);
|
osg::State::ApplyTextureModeProxy applyTextureMode(state, 0, GL_TEXTURE_2D, false);
|
||||||
|
|
||||||
|
state.disableAllVertexArrays();
|
||||||
state.setVertexPointer(_decorationVertices.get());
|
state.setVertexPointer(_decorationVertices.get());
|
||||||
|
|
||||||
unsigned int start_index = 0;
|
unsigned int start_index = 0;
|
||||||
@ -1222,6 +1311,13 @@ void Text::drawImplementation(osg::State& state, const osg::Vec4& colorMultiplie
|
|||||||
|
|
||||||
void Text::accept(osg::Drawable::ConstAttributeFunctor& af) const
|
void Text::accept(osg::Drawable::ConstAttributeFunctor& af) const
|
||||||
{
|
{
|
||||||
|
#ifdef NEW_APPROACH
|
||||||
|
if (_coords.valid() )
|
||||||
|
{
|
||||||
|
af.apply(osg::Drawable::VERTICES, _coords->size(), &(_coords->front()));
|
||||||
|
af.apply(osg::Drawable::TEXTURE_COORDS_0, _texcoords->size(), &(_texcoords->front()));
|
||||||
|
}
|
||||||
|
#else
|
||||||
// TODO what to do about local transforms?
|
// TODO what to do about local transforms?
|
||||||
for(TextureGlyphQuadMap::const_iterator titr=_textureGlyphQuadMap.begin();
|
for(TextureGlyphQuadMap::const_iterator titr=_textureGlyphQuadMap.begin();
|
||||||
titr!=_textureGlyphQuadMap.end();
|
titr!=_textureGlyphQuadMap.end();
|
||||||
@ -1234,10 +1330,21 @@ void Text::accept(osg::Drawable::ConstAttributeFunctor& af) const
|
|||||||
af.apply(osg::Drawable::TEXTURE_COORDS_0, glyphquad._texcoords->size(), &(glyphquad._texcoords->front()));
|
af.apply(osg::Drawable::TEXTURE_COORDS_0, glyphquad._texcoords->size(), &(glyphquad._texcoords->front()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void Text::accept(osg::PrimitiveFunctor& pf) const
|
void Text::accept(osg::PrimitiveFunctor& pf) const
|
||||||
{
|
{
|
||||||
|
#ifdef NEW_APPROACH
|
||||||
|
pf.setVertexArray(_coords->size(), &(_coords->front()));
|
||||||
|
for(TextureGlyphQuadMap::const_iterator titr=_textureGlyphQuadMap.begin();
|
||||||
|
titr!=_textureGlyphQuadMap.end();
|
||||||
|
++titr)
|
||||||
|
{
|
||||||
|
const GlyphQuads& glyphquad = titr->second;
|
||||||
|
pf.drawElements(GL_TRIANGLES, glyphquad._primitives[0]->size(), &(glyphquad._primitives[0]->front()));
|
||||||
|
}
|
||||||
|
#else
|
||||||
// TODO what to do about local transforms?
|
// TODO what to do about local transforms?
|
||||||
for(TextureGlyphQuadMap::const_iterator titr=_textureGlyphQuadMap.begin();
|
for(TextureGlyphQuadMap::const_iterator titr=_textureGlyphQuadMap.begin();
|
||||||
titr!=_textureGlyphQuadMap.end();
|
titr!=_textureGlyphQuadMap.end();
|
||||||
@ -1250,7 +1357,7 @@ void Text::accept(osg::PrimitiveFunctor& pf) const
|
|||||||
pf.drawArrays(GL_QUADS, 0, glyphquad._coords->size());
|
pf.drawArrays(GL_QUADS, 0, glyphquad._coords->size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1357,12 +1464,20 @@ float Text::bilinearInterpolate(float x1, float x2, float y1, float y2, float x,
|
|||||||
|
|
||||||
void Text::drawForegroundText(osg::State& state, const GlyphQuads& glyphquad, const osg::Vec4& colorMultiplier) const
|
void Text::drawForegroundText(osg::State& state, const GlyphQuads& glyphquad, const osg::Vec4& colorMultiplier) const
|
||||||
{
|
{
|
||||||
const GlyphQuads::Coords& transformedCoords = glyphquad._coords;
|
#ifdef NEW_APPROACH
|
||||||
|
const Coords& coords = _coords;
|
||||||
|
const TexCoords& texcoords = _texcoords;
|
||||||
|
const ColorCoords& colors = _colorCoords;
|
||||||
|
#else
|
||||||
|
const Coords& coords = glyphquad._coords;
|
||||||
|
const TexCoords& texcoords = glyphquad._texcoords;
|
||||||
|
const ColorCoords& colors = glyphquad._colorCoords;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (transformedCoords.valid() && !transformedCoords->empty())
|
if (coords.valid() && !coords->empty())
|
||||||
{
|
{
|
||||||
state.setVertexPointer(transformedCoords.get());
|
state.setVertexPointer(coords.get());
|
||||||
state.setTexCoordPointer(0, glyphquad._texcoords.get());
|
state.setTexCoordPointer(0, texcoords.get());
|
||||||
|
|
||||||
if(_colorGradientMode == SOLID)
|
if(_colorGradientMode == SOLID)
|
||||||
{
|
{
|
||||||
@ -1371,7 +1486,7 @@ void Text::drawForegroundText(osg::State& state, const GlyphQuads& glyphquad, co
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
state.setColorPointer(glyphquad._colorCoords.get());
|
state.setColorPointer(colors.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
glyphquad._primitives[0]->draw(state, _useVertexBufferObjects);
|
glyphquad._primitives[0]->draw(state, _useVertexBufferObjects);
|
||||||
@ -1423,6 +1538,11 @@ void Text::renderWithDelayedDepthWrites(osg::State& state, const osg::Vec4& colo
|
|||||||
|
|
||||||
void Text::drawTextWithBackdrop(osg::State& state, const osg::Vec4& colorMultiplier) const
|
void Text::drawTextWithBackdrop(osg::State& state, const osg::Vec4& colorMultiplier) const
|
||||||
{
|
{
|
||||||
|
#ifdef NEW_APPROACH
|
||||||
|
state.setVertexPointer(_coords.get());
|
||||||
|
state.setTexCoordPointer( 0, _texcoords.get());
|
||||||
|
#endif
|
||||||
|
|
||||||
for(TextureGlyphQuadMap::iterator titr=_textureGlyphQuadMap.begin();
|
for(TextureGlyphQuadMap::iterator titr=_textureGlyphQuadMap.begin();
|
||||||
titr!=_textureGlyphQuadMap.end();
|
titr!=_textureGlyphQuadMap.end();
|
||||||
++titr)
|
++titr)
|
||||||
@ -1438,23 +1558,27 @@ void Text::drawTextWithBackdrop(osg::State& state, const osg::Vec4& colorMultipl
|
|||||||
unsigned int max_backdrop_index;
|
unsigned int max_backdrop_index;
|
||||||
if(_backdropType == OUTLINE)
|
if(_backdropType == OUTLINE)
|
||||||
{
|
{
|
||||||
backdrop_index = 0;
|
backdrop_index = 1;
|
||||||
max_backdrop_index = 8;
|
max_backdrop_index = 8;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
backdrop_index = _backdropType;
|
backdrop_index = _backdropType+1;
|
||||||
max_backdrop_index = _backdropType+1;
|
max_backdrop_index = backdrop_index+1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (max_backdrop_index>glyphquad._primitives.size()) max_backdrop_index=glyphquad._primitives.size();
|
||||||
|
|
||||||
|
#ifndef NEW_APPROACH
|
||||||
state.setVertexPointer(glyphquad._coords.get());
|
state.setVertexPointer(glyphquad._coords.get());
|
||||||
state.setTexCoordPointer(0, glyphquad._texcoords.get());
|
state.setTexCoordPointer( 0, glyphquad._texcoords.get());
|
||||||
|
#endif
|
||||||
state.disableColorPointer();
|
state.disableColorPointer();
|
||||||
state.Color(_backdropColor.r(),_backdropColor.g(),_backdropColor.b(),_backdropColor.a());
|
state.Color(_backdropColor.r(),_backdropColor.g(),_backdropColor.b(),_backdropColor.a());
|
||||||
|
|
||||||
for( ; backdrop_index < max_backdrop_index; backdrop_index++)
|
for( ; backdrop_index < max_backdrop_index; backdrop_index++)
|
||||||
{
|
{
|
||||||
glyphquad._primitives[backdrop_index+1]->draw(state, _useVertexBufferObjects);
|
glyphquad._primitives[backdrop_index]->draw(state, _useVertexBufferObjects);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1472,6 +1596,11 @@ void Text::renderWithPolygonOffset(osg::State& state, const osg::Vec4& colorMult
|
|||||||
osg::PolygonOffset::setFactorAndUnitsMultipliersUsingBestGuessForDriver();
|
osg::PolygonOffset::setFactorAndUnitsMultipliersUsingBestGuessForDriver();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef NEW_APPROACH
|
||||||
|
state.setVertexPointer(_coords.get());
|
||||||
|
state.setTexCoordPointer( 0, _texcoords.get());
|
||||||
|
#endif
|
||||||
|
|
||||||
// Do I really need to do this for glPolygonOffset?
|
// Do I really need to do this for glPolygonOffset?
|
||||||
glPushAttrib(GL_POLYGON_OFFSET_FILL);
|
glPushAttrib(GL_POLYGON_OFFSET_FILL);
|
||||||
glEnable(GL_POLYGON_OFFSET_FILL);
|
glEnable(GL_POLYGON_OFFSET_FILL);
|
||||||
@ -1489,24 +1618,28 @@ void Text::renderWithPolygonOffset(osg::State& state, const osg::Vec4& colorMult
|
|||||||
unsigned int max_backdrop_index;
|
unsigned int max_backdrop_index;
|
||||||
if(_backdropType == OUTLINE)
|
if(_backdropType == OUTLINE)
|
||||||
{
|
{
|
||||||
backdrop_index = 0;
|
backdrop_index = 1;
|
||||||
max_backdrop_index = 8;
|
max_backdrop_index = 8;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
backdrop_index = _backdropType;
|
backdrop_index = _backdropType+1;
|
||||||
max_backdrop_index = _backdropType+1;
|
max_backdrop_index = backdrop_index+1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (max_backdrop_index>glyphquad._primitives.size()) max_backdrop_index=glyphquad._primitives.size();
|
||||||
|
|
||||||
|
#ifndef NEW_APPROACH
|
||||||
state.setVertexPointer(glyphquad._coords.get());
|
state.setVertexPointer(glyphquad._coords.get());
|
||||||
state.setTexCoordPointer( 0, glyphquad._texcoords.get());
|
state.setTexCoordPointer( 0, glyphquad._texcoords.get());
|
||||||
|
#endif
|
||||||
state.disableColorPointer();
|
state.disableColorPointer();
|
||||||
state.Color(_backdropColor.r(),_backdropColor.g(),_backdropColor.b(),_backdropColor.a());
|
state.Color(_backdropColor.r(),_backdropColor.g(),_backdropColor.b(),_backdropColor.a());
|
||||||
|
|
||||||
for( ; backdrop_index < max_backdrop_index; backdrop_index++)
|
for( ; backdrop_index < max_backdrop_index; backdrop_index++)
|
||||||
{
|
{
|
||||||
glPolygonOffset(0.1f * osg::PolygonOffset::getFactorMultiplier(), osg::PolygonOffset::getUnitsMultiplier() * (max_backdrop_index-backdrop_index) );
|
glPolygonOffset(0.1f * osg::PolygonOffset::getFactorMultiplier(), osg::PolygonOffset::getUnitsMultiplier() * (max_backdrop_index-backdrop_index) );
|
||||||
glyphquad._primitives[backdrop_index+1]->draw(state, _useVertexBufferObjects);
|
glyphquad._primitives[backdrop_index]->draw(state, _useVertexBufferObjects);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset the polygon offset so the foreground text is on top
|
// Reset the polygon offset so the foreground text is on top
|
||||||
@ -1529,6 +1662,11 @@ void Text::renderWithNoDepthBuffer(osg::State& state, const osg::Vec4& colorMult
|
|||||||
glPushAttrib(GL_DEPTH_BUFFER_BIT);
|
glPushAttrib(GL_DEPTH_BUFFER_BIT);
|
||||||
glDisable(GL_DEPTH_TEST);
|
glDisable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
|
#ifdef NEW_APPROACH
|
||||||
|
state.setVertexPointer(_coords.get());
|
||||||
|
state.setTexCoordPointer( 0, _texcoords.get());
|
||||||
|
#endif
|
||||||
|
|
||||||
for(TextureGlyphQuadMap::iterator titr=_textureGlyphQuadMap.begin();
|
for(TextureGlyphQuadMap::iterator titr=_textureGlyphQuadMap.begin();
|
||||||
titr!=_textureGlyphQuadMap.end();
|
titr!=_textureGlyphQuadMap.end();
|
||||||
++titr)
|
++titr)
|
||||||
@ -1542,23 +1680,27 @@ void Text::renderWithNoDepthBuffer(osg::State& state, const osg::Vec4& colorMult
|
|||||||
unsigned int max_backdrop_index;
|
unsigned int max_backdrop_index;
|
||||||
if(_backdropType == OUTLINE)
|
if(_backdropType == OUTLINE)
|
||||||
{
|
{
|
||||||
backdrop_index = 0;
|
backdrop_index = 1;
|
||||||
max_backdrop_index = 8;
|
max_backdrop_index = 8;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
backdrop_index = _backdropType;
|
backdrop_index = _backdropType+1;
|
||||||
max_backdrop_index = _backdropType+1;
|
max_backdrop_index = backdrop_index+1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (max_backdrop_index>glyphquad._primitives.size()) max_backdrop_index=glyphquad._primitives.size();
|
||||||
|
|
||||||
|
#ifndef NEW_APPROACH
|
||||||
state.setVertexPointer(glyphquad._coords.get());
|
state.setVertexPointer(glyphquad._coords.get());
|
||||||
state.setTexCoordPointer( 0, glyphquad._texcoords.get());
|
state.setTexCoordPointer( 0, glyphquad._texcoords.get());
|
||||||
|
#endif
|
||||||
state.disableColorPointer();
|
state.disableColorPointer();
|
||||||
state.Color(_backdropColor.r(),_backdropColor.g(),_backdropColor.b(),_backdropColor.a());
|
state.Color(_backdropColor.r(),_backdropColor.g(),_backdropColor.b(),_backdropColor.a());
|
||||||
|
|
||||||
for( ; backdrop_index < max_backdrop_index; backdrop_index++)
|
for( ; backdrop_index < max_backdrop_index; backdrop_index++)
|
||||||
{
|
{
|
||||||
glyphquad._primitives[backdrop_index+1]->draw(state, _useVertexBufferObjects);
|
glyphquad._primitives[backdrop_index]->draw(state, _useVertexBufferObjects);
|
||||||
}
|
}
|
||||||
|
|
||||||
drawForegroundText(state, glyphquad, colorMultiplier);
|
drawForegroundText(state, glyphquad, colorMultiplier);
|
||||||
@ -1580,6 +1722,11 @@ void Text::renderWithDepthRange(osg::State& state, const osg::Vec4& colorMultipl
|
|||||||
// glPushAttrib(GL_VIEWPORT_BIT);
|
// glPushAttrib(GL_VIEWPORT_BIT);
|
||||||
glPushAttrib(GL_DEPTH_BUFFER_BIT);
|
glPushAttrib(GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
|
#ifdef NEW_APPROACH
|
||||||
|
state.setVertexPointer(_coords.get());
|
||||||
|
state.setTexCoordPointer( 0, _texcoords.get());
|
||||||
|
#endif
|
||||||
|
|
||||||
for(TextureGlyphQuadMap::iterator titr=_textureGlyphQuadMap.begin();
|
for(TextureGlyphQuadMap::iterator titr=_textureGlyphQuadMap.begin();
|
||||||
titr!=_textureGlyphQuadMap.end();
|
titr!=_textureGlyphQuadMap.end();
|
||||||
++titr)
|
++titr)
|
||||||
@ -1593,17 +1740,21 @@ void Text::renderWithDepthRange(osg::State& state, const osg::Vec4& colorMultipl
|
|||||||
unsigned int max_backdrop_index;
|
unsigned int max_backdrop_index;
|
||||||
if(_backdropType == OUTLINE)
|
if(_backdropType == OUTLINE)
|
||||||
{
|
{
|
||||||
backdrop_index = 0;
|
backdrop_index = 1;
|
||||||
max_backdrop_index = 8;
|
max_backdrop_index = 8;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
backdrop_index = _backdropType;
|
backdrop_index = _backdropType+1;
|
||||||
max_backdrop_index = _backdropType+1;
|
max_backdrop_index = backdrop_index+1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (max_backdrop_index>glyphquad._primitives.size()) max_backdrop_index=glyphquad._primitives.size();
|
||||||
|
|
||||||
|
#ifndef NEW_APPROACH
|
||||||
state.setVertexPointer(glyphquad._coords.get());
|
state.setVertexPointer(glyphquad._coords.get());
|
||||||
state.setTexCoordPointer( 0, glyphquad._texcoords.get());
|
state.setTexCoordPointer( 0, glyphquad._texcoords.get());
|
||||||
|
#endif
|
||||||
state.disableColorPointer();
|
state.disableColorPointer();
|
||||||
state.Color(_backdropColor.r(),_backdropColor.g(),_backdropColor.b(),_backdropColor.a());
|
state.Color(_backdropColor.r(),_backdropColor.g(),_backdropColor.b(),_backdropColor.a());
|
||||||
|
|
||||||
@ -1611,7 +1762,7 @@ void Text::renderWithDepthRange(osg::State& state, const osg::Vec4& colorMultipl
|
|||||||
{
|
{
|
||||||
double offset = double(max_backdrop_index-backdrop_index)*0.0001;
|
double offset = double(max_backdrop_index-backdrop_index)*0.0001;
|
||||||
glDepthRange( offset, 1.0+offset);
|
glDepthRange( offset, 1.0+offset);
|
||||||
glyphquad._primitives[backdrop_index+1]->draw(state, _useVertexBufferObjects);
|
glyphquad._primitives[backdrop_index]->draw(state, _useVertexBufferObjects);
|
||||||
}
|
}
|
||||||
|
|
||||||
glDepthRange(0.0, 1.0);
|
glDepthRange(0.0, 1.0);
|
||||||
@ -1669,6 +1820,10 @@ void Text::renderWithStencilBuffer(osg::State& state, const osg::Vec4& colorMult
|
|||||||
// Arrrgh! Why does the code only seem to work correctly if I call this?
|
// Arrrgh! Why does the code only seem to work correctly if I call this?
|
||||||
glDepthMask(GL_FALSE);
|
glDepthMask(GL_FALSE);
|
||||||
|
|
||||||
|
#ifdef NEW_APPROACH
|
||||||
|
state.setVertexPointer(_coords.get());
|
||||||
|
state.setTexCoordPointer( 0, _texcoords.get());
|
||||||
|
#endif
|
||||||
|
|
||||||
// Draw all the text to the stencil buffer to mark out the region
|
// Draw all the text to the stencil buffer to mark out the region
|
||||||
// that we can write too.
|
// that we can write too.
|
||||||
@ -1686,27 +1841,29 @@ void Text::renderWithStencilBuffer(osg::State& state, const osg::Vec4& colorMult
|
|||||||
unsigned int max_backdrop_index;
|
unsigned int max_backdrop_index;
|
||||||
if(_backdropType == OUTLINE)
|
if(_backdropType == OUTLINE)
|
||||||
{
|
{
|
||||||
backdrop_index = 0;
|
backdrop_index = 1;
|
||||||
max_backdrop_index = 8;
|
max_backdrop_index = 8;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
backdrop_index = _backdropType;
|
backdrop_index = _backdropType+1;
|
||||||
max_backdrop_index = _backdropType+1;
|
max_backdrop_index = backdrop_index+1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (max_backdrop_index>glyphquad._primitives.size()) max_backdrop_index=glyphquad._primitives.size();
|
||||||
|
|
||||||
|
#ifndef NEW_APPROACH
|
||||||
state.setVertexPointer(glyphquad._coords.get());
|
state.setVertexPointer(glyphquad._coords.get());
|
||||||
state.setTexCoordPointer( 0, glyphquad._texcoords.get());
|
state.setTexCoordPointer( 0, glyphquad._texcoords.get());
|
||||||
|
#endif
|
||||||
state.disableColorPointer();
|
state.disableColorPointer();
|
||||||
|
|
||||||
for( ; backdrop_index < max_backdrop_index; backdrop_index++)
|
for( ; backdrop_index < max_backdrop_index; backdrop_index++)
|
||||||
{
|
{
|
||||||
glyphquad._primitives[backdrop_index+1]->draw(state, _useVertexBufferObjects);
|
glyphquad._primitives[backdrop_index]->draw(state, _useVertexBufferObjects);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw the foreground text
|
// Draw the foreground text
|
||||||
state.setVertexPointer( glyphquad._coords.get());
|
|
||||||
state.setTexCoordPointer( 0, glyphquad._texcoords.get());
|
|
||||||
glyphquad._primitives[0]->draw(state, _useVertexBufferObjects);
|
glyphquad._primitives[0]->draw(state, _useVertexBufferObjects);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1729,6 +1886,10 @@ void Text::renderWithStencilBuffer(osg::State& state, const osg::Vec4& colorMult
|
|||||||
// Re-enable writing to the color buffer so we can see the results
|
// Re-enable writing to the color buffer so we can see the results
|
||||||
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
||||||
|
|
||||||
|
#ifdef NEW_APPROACH
|
||||||
|
state.setVertexPointer(_coords.get());
|
||||||
|
state.setTexCoordPointer( 0, _texcoords.get());
|
||||||
|
#endif
|
||||||
|
|
||||||
// Draw all the text again
|
// Draw all the text again
|
||||||
|
|
||||||
@ -1745,23 +1906,27 @@ void Text::renderWithStencilBuffer(osg::State& state, const osg::Vec4& colorMult
|
|||||||
unsigned int max_backdrop_index;
|
unsigned int max_backdrop_index;
|
||||||
if(_backdropType == OUTLINE)
|
if(_backdropType == OUTLINE)
|
||||||
{
|
{
|
||||||
backdrop_index = 0;
|
backdrop_index = 1;
|
||||||
max_backdrop_index = 8;
|
max_backdrop_index = 8;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
backdrop_index = _backdropType;
|
backdrop_index = _backdropType+1;
|
||||||
max_backdrop_index = _backdropType+1;
|
max_backdrop_index = backdrop_index+1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (max_backdrop_index>glyphquad._primitives.size()) max_backdrop_index=glyphquad._primitives.size();
|
||||||
|
|
||||||
|
#ifndef NEW_APPROACH
|
||||||
state.setVertexPointer(glyphquad._coords.get());
|
state.setVertexPointer(glyphquad._coords.get());
|
||||||
state.setTexCoordPointer( 0, glyphquad._texcoords.get());
|
state.setTexCoordPointer( 0, glyphquad._texcoords.get());
|
||||||
|
#endif
|
||||||
state.disableColorPointer();
|
state.disableColorPointer();
|
||||||
state.Color(_backdropColor.r(),_backdropColor.g(),_backdropColor.b(),_backdropColor.a());
|
state.Color(_backdropColor.r(),_backdropColor.g(),_backdropColor.b(),_backdropColor.a());
|
||||||
|
|
||||||
for( ; backdrop_index < max_backdrop_index; backdrop_index++)
|
for( ; backdrop_index < max_backdrop_index; backdrop_index++)
|
||||||
{
|
{
|
||||||
glyphquad._primitives[backdrop_index+1]->draw(state, _useVertexBufferObjects);
|
glyphquad._primitives[backdrop_index]->draw(state, _useVertexBufferObjects);
|
||||||
}
|
}
|
||||||
|
|
||||||
drawForegroundText(state, glyphquad, colorMultiplier);
|
drawForegroundText(state, glyphquad, colorMultiplier);
|
||||||
@ -1785,29 +1950,35 @@ Text::GlyphQuads::GlyphQuads(const GlyphQuads&)
|
|||||||
|
|
||||||
void Text::GlyphQuads::initGlyphQuads()
|
void Text::GlyphQuads::initGlyphQuads()
|
||||||
{
|
{
|
||||||
|
_coordBase = 0;
|
||||||
|
#ifndef NEW_APPROACH
|
||||||
_coords = new osg::Vec3Array();
|
_coords = new osg::Vec3Array();
|
||||||
_texcoords = new osg::Vec2Array();
|
_texcoords = new osg::Vec2Array();
|
||||||
_colorCoords = new osg::Vec4Array();
|
_colorCoords = new osg::Vec4Array();
|
||||||
|
#endif
|
||||||
|
_primitives.push_back(new DrawElementsUShort(PrimitiveSet::TRIANGLES));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Text::GlyphQuads::setupPrimitives(BackdropType backdropType)
|
void Text::GlyphQuads::setupPrimitives(BackdropType backdropType)
|
||||||
{
|
{
|
||||||
OSG_NOTICE<<"Text::GlyphQuads::setupPrimitives() _glyphs.size()="<<_glyphs.size()<<", "<<_coords->size()<<std::endl;
|
OSG_NOTICE<<"Text::GlyphQuads::setupPrimitives() _glyphs.size()="<<_glyphs.size()<<std::endl;
|
||||||
|
|
||||||
_primitives.clear();
|
// _primitives.clear();
|
||||||
|
|
||||||
|
return;
|
||||||
|
|
||||||
unsigned int numCoords = _glyphs.size()*4;
|
unsigned int numCoords = _glyphs.size()*4;
|
||||||
|
|
||||||
unsigned int numPrimtives = 1;
|
unsigned int numBackdrops = 0;
|
||||||
if (backdropType==Text::OUTLINE) numPrimtives += 8;
|
if (backdropType==Text::OUTLINE) numBackdrops += 8;
|
||||||
if (backdropType!=Text::NONE) numPrimtives += 1;
|
if (backdropType!=Text::NONE) numBackdrops += 1;
|
||||||
|
|
||||||
for(unsigned int i=0; i<numPrimtives; ++i)
|
for(unsigned int i=0; i<numBackdrops; ++i)
|
||||||
{
|
{
|
||||||
_primitives.push_back(new DrawElementsUShort(PrimitiveSet::TRIANGLES));
|
_primitives.push_back(new DrawElementsUShort(PrimitiveSet::TRIANGLES));
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int baseIndex = 0;
|
unsigned int baseIndex = _coordBase;
|
||||||
for(Primitives::iterator itr = _primitives.begin();
|
for(Primitives::iterator itr = _primitives.begin();
|
||||||
itr != _primitives.end();
|
itr != _primitives.end();
|
||||||
++itr)
|
++itr)
|
||||||
@ -1832,6 +2003,7 @@ void Text::GlyphQuads::setupPrimitives(BackdropType backdropType)
|
|||||||
|
|
||||||
void Text::GlyphQuads::initGPUBufferObjects()
|
void Text::GlyphQuads::initGPUBufferObjects()
|
||||||
{
|
{
|
||||||
|
#ifndef NEW_APPROACH
|
||||||
osg::VertexBufferObject* vbo = new osg::VertexBufferObject();
|
osg::VertexBufferObject* vbo = new osg::VertexBufferObject();
|
||||||
_coords->setBinding(osg::Array::BIND_PER_VERTEX);
|
_coords->setBinding(osg::Array::BIND_PER_VERTEX);
|
||||||
_coords->setVertexBufferObject(vbo);
|
_coords->setVertexBufferObject(vbo);
|
||||||
@ -1839,7 +2011,7 @@ void Text::GlyphQuads::initGPUBufferObjects()
|
|||||||
_texcoords->setVertexBufferObject(vbo);
|
_texcoords->setVertexBufferObject(vbo);
|
||||||
_colorCoords->setBinding(osg::Array::BIND_PER_VERTEX);
|
_colorCoords->setBinding(osg::Array::BIND_PER_VERTEX);
|
||||||
_colorCoords->setVertexBufferObject(vbo);
|
_colorCoords->setVertexBufferObject(vbo);
|
||||||
|
#endif
|
||||||
osg::ref_ptr<osg::ElementBufferObject> ebo = new osg::ElementBufferObject();
|
osg::ref_ptr<osg::ElementBufferObject> ebo = new osg::ElementBufferObject();
|
||||||
for(Primitives::iterator itr = _primitives.begin();
|
for(Primitives::iterator itr = _primitives.begin();
|
||||||
itr != _primitives.end();
|
itr != _primitives.end();
|
||||||
@ -1853,9 +2025,11 @@ void Text::GlyphQuads::initGPUBufferObjects()
|
|||||||
|
|
||||||
void Text::GlyphQuads::resizeGLObjectBuffers(unsigned int maxSize)
|
void Text::GlyphQuads::resizeGLObjectBuffers(unsigned int maxSize)
|
||||||
{
|
{
|
||||||
|
#ifndef NEW_APPROACH
|
||||||
_coords->resizeGLObjectBuffers(maxSize);
|
_coords->resizeGLObjectBuffers(maxSize);
|
||||||
_texcoords->resizeGLObjectBuffers(maxSize);
|
_texcoords->resizeGLObjectBuffers(maxSize);
|
||||||
_colorCoords->resizeGLObjectBuffers(maxSize);
|
_colorCoords->resizeGLObjectBuffers(maxSize);
|
||||||
|
#endif
|
||||||
|
|
||||||
for(Primitives::iterator itr = _primitives.begin();
|
for(Primitives::iterator itr = _primitives.begin();
|
||||||
itr != _primitives.end();
|
itr != _primitives.end();
|
||||||
@ -1869,9 +2043,11 @@ void Text::GlyphQuads::resizeGLObjectBuffers(unsigned int maxSize)
|
|||||||
|
|
||||||
void Text::GlyphQuads::releaseGLObjects(osg::State* state) const
|
void Text::GlyphQuads::releaseGLObjects(osg::State* state) const
|
||||||
{
|
{
|
||||||
|
#ifndef NEW_APPROACH
|
||||||
_coords->releaseGLObjects(state);;
|
_coords->releaseGLObjects(state);;
|
||||||
_texcoords->releaseGLObjects(state);
|
_texcoords->releaseGLObjects(state);
|
||||||
_colorCoords->releaseGLObjects(state);
|
_colorCoords->releaseGLObjects(state);
|
||||||
|
#endif
|
||||||
|
|
||||||
for(Primitives::const_iterator itr = _primitives.begin();
|
for(Primitives::const_iterator itr = _primitives.begin();
|
||||||
itr != _primitives.end();
|
itr != _primitives.end();
|
||||||
|
@ -123,18 +123,27 @@ void Input::_calculateCursorOffsets() {
|
|||||||
const osgText::Text::GlyphQuads& gq = tgqmi->second;
|
const osgText::Text::GlyphQuads& gq = tgqmi->second;
|
||||||
|
|
||||||
//coords.insert(coords.end(),gq.getTransformedCoords(0).begin(),gq.getTransformedCoords(0).end());
|
//coords.insert(coords.end(),gq.getTransformedCoords(0).begin(),gq.getTransformedCoords(0).end());
|
||||||
|
#ifndef NEW_APPROACH
|
||||||
unsigned int numCoords = gq.getCoords()->size();
|
unsigned int numCoords = gq.getCoords()->size();
|
||||||
for(unsigned int i=0; i<numCoords; ++i)
|
for(unsigned int i=0; i<numCoords; ++i)
|
||||||
{
|
{
|
||||||
osg::Vec2 c; gq.getCoord(i, c); coords.push_back(c);
|
osg::Vec2 c; gq.getCoord(i, c); coords.push_back(c);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
for (unsigned int i=0; i<gq.getGlyphs().size(); ++i)
|
for (unsigned int i=0; i<gq.getGlyphs().size(); ++i)
|
||||||
{
|
{
|
||||||
glyphs.push_back(gq.getGlyphs().at(i));
|
glyphs.push_back(gq.getGlyphs().at(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef NEW_APPROACH
|
||||||
|
unsigned int numCoords = _text->getCoords()->size();
|
||||||
|
for(unsigned int i=0; i<numCoords; ++i)
|
||||||
|
{
|
||||||
|
osg::Vec2 c; _text->getCoord(i, c); coords.push_back(c);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
std::list<unsigned int> keys;
|
std::list<unsigned int> keys;
|
||||||
for (unsigned int i=0; i<_text->getText().size(); ++i)
|
for (unsigned int i=0; i<_text->getText().size(); ++i)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user