diff --git a/examples/osgtext3D/osgtext3D.cpp b/examples/osgtext3D/osgtext3D.cpp index 7495064e4..8c9705756 100644 --- a/examples/osgtext3D/osgtext3D.cpp +++ b/examples/osgtext3D/osgtext3D.cpp @@ -238,10 +238,22 @@ int main(int argc, char** argv) geode->addDrawable( osg::createTexturedQuadGeometry(osg::Vec3(0.0f,characterSize*thickness,0.0f),osg::Vec3(characterSize,0.0,0.0),osg::Vec3(0.0f,0.0,characterSize), 0.0, 0.0, 1.0, 1.0) ); } + if (arguments.read("--add-axes")) + group->addChild(osgDB::readNodeFile("axes.osgt")); + + std::string mode; + if (arguments.read("--character-size-mode", mode)) + { + if (mode == "screen_coords") + { + text3D->setCharacterSizeMode(osgText::TextBase::SCREEN_COORDS); + text3D->setCharacterSize(1080/4); + } + } + viewer.addEventHandler(new Text3DAttributeHandler(text3D)); } - viewer.setSceneData(group); #endif diff --git a/include/osgText/TextBase b/include/osgText/TextBase index 15675c76e..64fe785f1 100644 --- a/include/osgText/TextBase +++ b/include/osgText/TextBase @@ -325,12 +325,12 @@ protected: osg::Vec4 _textBBColor; KerningType _kerningType; unsigned int _lineCount; + bool _glyphNormalized; osg::Vec3 _offset; osg::Vec3 _normal; osg::BoundingBox _textBB; - mutable osg::Matrix _matrix; Primitives _decorationPrimitives; diff --git a/src/osgText/Text3D.cpp b/src/osgText/Text3D.cpp index ce94840fb..7cbe23f55 100644 --- a/src/osgText/Text3D.cpp +++ b/src/osgText/Text3D.cpp @@ -21,12 +21,14 @@ namespace osgText Text3D::Text3D(): _renderMode(PER_GLYPH) { + _glyphNormalized = true; } Text3D::Text3D(const Text3D & text3D, const osg::CopyOp & copyop): osgText::TextBase(text3D, copyop), _renderMode(text3D._renderMode) { + _glyphNormalized = text3D._glyphNormalized; computeGlyphRepresentation(); } diff --git a/src/osgText/TextBase.cpp b/src/osgText/TextBase.cpp index f93184828..5c5e5460e 100644 --- a/src/osgText/TextBase.cpp +++ b/src/osgText/TextBase.cpp @@ -47,7 +47,8 @@ TextBase::TextBase(): _textBBMargin(0.0f), _textBBColor(0.0, 0.0, 0.0, 0.5), _kerningType(KERNING_DEFAULT), - _lineCount(0) + _lineCount(0), + _glyphNormalized(false) { setStateSet(Font::getDefaultFont()->getStateSet()); setUseDisplayList(false); @@ -78,7 +79,8 @@ TextBase::TextBase(const TextBase& textBase,const osg::CopyOp& copyop): _textBBMargin(textBase._textBBMargin), _textBBColor(textBase._textBBColor), _kerningType(textBase._kerningType), - _lineCount(textBase._lineCount) + _lineCount(textBase._lineCount), + _glyphNormalized(textBase._glyphNormalized) { initArraysAndBuffers(); } @@ -537,6 +539,12 @@ bool TextBase::computeMatrix(osg::Matrix& matrix, osg::State* state) const if (pixelSizeHori == 0.0f) pixelSizeHori= 1.0f; + if (_glyphNormalized) + { + osg::Vec3 scaleVec(_characterHeight/getCharacterAspectRatio(), _characterHeight, _characterHeight); + matrix.postMultScale(scaleVec); + } + if (_characterSizeMode==SCREEN_COORDS) { float scale_font_vert=_characterHeight/pixelSizeVert; @@ -544,12 +552,12 @@ bool TextBase::computeMatrix(osg::Matrix& matrix, osg::State* state) const if (P10<0) scale_font_vert=-scale_font_vert; - matrix.postMultScale(osg::Vec3f(scale_font_hori, scale_font_vert,1.0f)); + matrix.postMultScale(osg::Vec3f(scale_font_hori, scale_font_vert, scale_font_hori)); } else if (pixelSizeVert>getFontHeight()) { float scale_font = getFontHeight()/pixelSizeVert; - matrix.postMultScale(osg::Vec3f(scale_font, scale_font,1.0f)); + matrix.postMultScale(osg::Vec3f(scale_font, scale_font, scale_font)); } } @@ -560,17 +568,29 @@ bool TextBase::computeMatrix(osg::Matrix& matrix, osg::State* state) const } matrix.postMultTranslate(_position); + } else if (!_rotation.zeroRotation()) { - matrix.makeRotate(_rotation); - matrix.preMultTranslate(-_offset); + matrix.makeTranslate(-_offset); + if (_glyphNormalized) + { + osg::Vec3 scaleVec(_characterHeight/getCharacterAspectRatio(), _characterHeight, _characterHeight); + matrix.postMultScale(scaleVec); + } + matrix.postMultRotate(_rotation); matrix.postMultTranslate(_position); // OSG_NOTICE<<"New Need to rotate "<