diff --git a/examples/osgtext/osgtext.cpp b/examples/osgtext/osgtext.cpp index b6865f6a6..3742e6dc1 100644 --- a/examples/osgtext/osgtext.cpp +++ b/examples/osgtext/osgtext.cpp @@ -12,13 +12,17 @@ */ #include + #include -#include +#include + #include #include #include #include +#include +#include #include #include @@ -27,9 +31,12 @@ osg::Group* createHUDText() { + osg::Group* rootNode = new osg::Group; + osgText::Font* font = osgText::readFontFile("fonts/arial.ttf"); osg::Geode* geode = new osg::Geode; + rootNode->addChild(geode); float windowHeight = 1024.0f; float windowWidth = 1280.0f; @@ -141,17 +148,17 @@ osg::Group* createHUDText() osgText::Text* text = new osgText::Text; text->setFont(font); text->setColor(characterSizeColor); - text->setFontSize(15,15); + text->setFontSize(20,20); text->setPosition(cursor); - // use text that 15 units high. - text->setCharacterSize(15); // tiny + // use text that 20 units high. + text->setCharacterSize(20); // small - text->setText("text->setCharacterSize(15.0f); // tiny"); + text->setText("text->setCharacterSize(15.0f); // small"); geode->addDrawable(text); } - cursor.y() -= fontSizeCharacterSize; + cursor.y() -= 30.0f; { osgText::Text* text = new osgText::Text; text->setFont(font); @@ -159,14 +166,14 @@ osg::Group* createHUDText() text->setFontSize(30,30); text->setPosition(cursor); - // use text that uses 10 by 10 texels as a target resolution for fonts. - text->setCharacterSize(30.0f); // tiny + // use text that 20 units high. + text->setCharacterSize(30.0f); // medium - text->setText("text->setCharacterSize(30.0f); // medium size"); + text->setText("text->setCharacterSize(30.0f); // medium"); geode->addDrawable(text); } - cursor.y() -= fontSizeCharacterSize; + cursor.y() -= 50.0f; { osgText::Text* text = new osgText::Text; text->setFont(font); @@ -175,64 +182,51 @@ osg::Group* createHUDText() text->setPosition(cursor); // use text that uses 10 by 10 texels as a target resolution for fonts. - text->setCharacterSize(40.0f); // tiny + text->setCharacterSize(60.0f); // large - text->setText("text->setCharacterSize(40.0f); // big, but can go much bigger :-)"); + text->setText("text->setCharacterSize(60.0f); // large"); geode->addDrawable(text); } + cursor.x() = 500; + cursor.y() = margin; -if (0) -{ - osgText::Text* text2 = new osgText::Text; - text2->setPosition(osg::Vec3(0.0f,50.0f,0.0f)); - text2->setCharacterSize(12.0f); - text2->setText("10 PRINT \"Hello World\""); - geode->addDrawable(text2); - - osgText::Text* text3 = new osgText::Text; - text3->setFont(osgText::readFontFile("fonts/arial.ttf")); - text3->setPosition(osg::Vec3(100.0f,100.0f,0.0f)); - text3->setText("This is a test of text AVAV/.|¬!£$%^&*() - fonts/arial.ttf"); - geode->addDrawable(text3); - - osgText::Text* text4 = new osgText::Text; - text4->setFont(osgText::readFontFile("fonts/times.ttf")); - text4->setFontSize(128,128); - text4->setPosition(osg::Vec3(200.0f,200.0f,0.0f)); - text4->setLayout(osgText::Text::RIGHT_TO_LEFT); - text4->setDrawMode(osgText::Text::TEXT|osgText::Text::ALIGNMENT|osgText::Text::BOUNDINGBOX); - text4->setText("This is a test of text AVAV/.|¬!£$%^&*() - fonts/times.ttf"); - geode->addDrawable(text4); - - osgText::Text* text5 = new osgText::Text; - text5->setFont(osgText::readFontFile("fonts/dirtydoz.ttf")); - text5->setPosition(osg::Vec3(300.0f,300.0f,0.0f)); - text5->setColor(osg::Vec4(1.0f,0.0f,0.0f,1.0f)); - text5->setLayout(osgText::Text::VERTICAL); - text5->setDrawMode(osgText::Text::TEXT|osgText::Text::ALIGNMENT|osgText::Text::BOUNDINGBOX); - text5->setText("This is a test of text AVAV/.|¬!£$%^&*() - fonts/dirtydoz.ttf"); - geode->addDrawable(text5); -} - -// osgText::Text::TextString string; -// for(int i=0;i<2048;++i) -// string.push_back(i); -// -// osgText::Text* text6 = new osgText::Text; -// text6->setFont(osgText::readFontFile("/home/robert/Documents/GuopingSun/msmincho.ttc")); -// text6->setFontSize(64,64); -// text6->setText(string); -// text6->setPosition(osg::Vec3(00.0f,400.0f,0.0f)); -// geode->addDrawable(text6); - + osg::Sequence* sequence = new osg::Sequence; + + sequence->setMode(osg::Sequence::START); + sequence->setInterval(osg::Sequence::LOOP, 0, -1); + sequence->setDuration(1.0f, -1); +// osg::Group* sequence = new osg::Group; +// rootNode->addChild(sequence); + + { + for(unsigned int i=osgText::Text::LEFT_TOP;i<=osgText::Text::BASE_LINE;i++) + { + osg::Geode* alignmentGeode = new osg::Geode; + sequence->addChild(alignmentGeode); + sequence->setTime(i, 1.0f); + + osgText::Text* text = new osgText::Text; + text->setFont(font); + text->setColor(characterSizeColor); + text->setPosition(cursor); + text->setDrawMode(osgText::Text::TEXT|osgText::Text::ALIGNMENT|osgText::Text::BOUNDINGBOX); + + text->setAlignment((osgText::Text::AlignmentType)i); + + text->setText("text->setAlignment();"); + alignmentGeode->addDrawable(text); + + cursor.y() += 40.0f; - osg::Group* rootNode = new osg::Group; - rootNode->addChild(geode); - + } + + } + rootNode->addChild(sequence); + return rootNode; } @@ -261,13 +255,20 @@ osg::Group* create3DText() text3->setText("XZ_PLANE"); geode->addDrawable(text3); + + osg::Vec3 screenCenter(300.0f,00.0f,00.0f); osgText::Text* text4 = new osgText::Text; text4->setFont("fonts/times.ttf"); text4->setAxisAlignment(osgText::Text::SCREEN); - text4->setPosition(osg::Vec3(00.0f,00.0f,00.0f)); + text4->setPosition(screenCenter); text4->setText("SCREEN"); geode->addDrawable(text4); + osg::ShapeDrawable* shape = new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(screenCenter),2.0f)); + shape->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::ON); + geode->addDrawable(shape); + + osg::Group* rootNode = new osg::Group; rootNode->addChild(geode); @@ -361,6 +362,8 @@ int main( int argc, char **argv ) // set the scene to render viewer.setSceneData(rootNode.get()); + osgDB::writeNodeFile(*rootNode,"test.osg"); + // create the windows and run the threads. viewer.realize(Producer::CameraGroup::ThreadPerCamera); diff --git a/include/osgText/Text b/include/osgText/Text index f48f7f045..b2a6d068b 100644 --- a/include/osgText/Text +++ b/include/osgText/Text @@ -81,7 +81,7 @@ public: ENCODING_UTF32, /// 32-bit signature ENCODING_UTF32_BE, /// 32-bit big-endian ENCODING_UTF32_LE, /// 32-bit little-endian - ENCODING_SIGNATURE, /// detect encoding from signature + ENCODING_SIGNATURE /// detect encoding from signature }; /** Set the text using a Unicode encoded std::string, which is converted to an internal TextString. diff --git a/src/osgPlugins/freetype/ReaderWriterFreeType.cpp b/src/osgPlugins/freetype/ReaderWriterFreeType.cpp index a1b8936e5..3410e67be 100644 --- a/src/osgPlugins/freetype/ReaderWriterFreeType.cpp +++ b/src/osgPlugins/freetype/ReaderWriterFreeType.cpp @@ -4,7 +4,7 @@ #include "FreeTypeLibrary.h" class ReaderWriterFreeType : public osgDB::ReaderWriter -{; +{ public: virtual const char* className() { return "FreeType Font Reader/Writer"; } diff --git a/src/osgPlugins/osgText/IO_Text.cpp b/src/osgPlugins/osgText/IO_Text.cpp index 1fcd1334d..4fc0b5846 100644 --- a/src/osgPlugins/osgText/IO_Text.cpp +++ b/src/osgPlugins/osgText/IO_Text.cpp @@ -114,7 +114,8 @@ bool Text_writeLocalData(const osg::Object &obj, osgDB::Output &fw) } if (isACString) { - std::string str(textstring.begin(),textstring.end()); + std::string str; + std::copy(textstring.begin(),textstring.end(),std::back_inserter(str)); fw.indent() << "text " << fw.wrapString(str) << std::endl; } else diff --git a/src/osgText/Text.cpp b/src/osgText/Text.cpp index ccd0d4217..95167c46a 100644 --- a/src/osgText/Text.cpp +++ b/src/osgText/Text.cpp @@ -104,7 +104,7 @@ void Text::setText(const TextString& text) void Text::setText(const std::string& text) { _text.clear(); - _text.insert(_text.end(),text.begin(),text.end()); + std::copy(text.begin(),text.end(),std::back_inserter(_text)); computeGlyphRepresentation(); } @@ -140,7 +140,7 @@ void Text::setText(const wchar_t* text) while (*endOfText) ++endOfText; // pass it to the _text field. - _text.insert(_text.end(),text,endOfText); + std::copy(text,endOfText,std::back_inserter(_text)); } computeGlyphRepresentation(); }