2003-02-21 22:05:39 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
|
|
|
|
*
|
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <osgUtil/Optimizer>
|
2003-03-05 17:08:11 +08:00
|
|
|
|
2003-02-21 22:05:39 +08:00
|
|
|
#include <osgDB/ReadFile>
|
2003-03-05 17:08:11 +08:00
|
|
|
#include <osgDB/WriteFile>
|
2003-03-07 01:11:24 +08:00
|
|
|
#include <osgDB/Registry>
|
2003-03-05 17:08:11 +08:00
|
|
|
|
2003-02-21 22:05:39 +08:00
|
|
|
#include <osgProducer/Viewer>
|
|
|
|
|
|
|
|
#include <osg/Geode>
|
|
|
|
#include <osg/Projection>
|
|
|
|
#include <osg/MatrixTransform>
|
2003-03-05 17:08:11 +08:00
|
|
|
#include <osg/ShapeDrawable>
|
|
|
|
#include <osg/Sequence>
|
2003-02-21 22:05:39 +08:00
|
|
|
|
2003-03-05 01:14:42 +08:00
|
|
|
#include <osgText/Font>
|
2003-03-03 05:05:05 +08:00
|
|
|
#include <osgText/Text>
|
2003-02-21 22:05:39 +08:00
|
|
|
|
|
|
|
|
2003-03-03 05:05:05 +08:00
|
|
|
osg::Group* createHUDText()
|
2003-02-21 22:05:39 +08:00
|
|
|
{
|
|
|
|
|
2003-03-05 17:08:11 +08:00
|
|
|
osg::Group* rootNode = new osg::Group;
|
|
|
|
|
2003-03-05 01:14:42 +08:00
|
|
|
osgText::Font* font = osgText::readFontFile("fonts/arial.ttf");
|
|
|
|
|
2003-03-03 05:05:05 +08:00
|
|
|
osg::Geode* geode = new osg::Geode;
|
2003-03-05 17:08:11 +08:00
|
|
|
rootNode->addChild(geode);
|
2003-03-03 05:05:05 +08:00
|
|
|
|
2003-03-05 01:14:42 +08:00
|
|
|
float windowHeight = 1024.0f;
|
|
|
|
float windowWidth = 1280.0f;
|
|
|
|
float margin = 50.0f;
|
2003-03-03 05:05:05 +08:00
|
|
|
|
2003-03-05 01:14:42 +08:00
|
|
|
|
2003-03-05 20:28:42 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Examples of how to set up different text layout
|
|
|
|
//
|
|
|
|
|
2003-03-05 01:14:42 +08:00
|
|
|
osg::Vec4 layoutColor(1.0f,1.0f,0.0f,1.0f);
|
|
|
|
float layoutCharacterSize = 20.0f;
|
|
|
|
|
|
|
|
{
|
|
|
|
osgText::Text* text = new osgText::Text;
|
|
|
|
text->setFont(font);
|
|
|
|
text->setColor(layoutColor);
|
|
|
|
text->setCharacterSize(layoutCharacterSize);
|
|
|
|
text->setPosition(osg::Vec3(margin,windowHeight-margin,0.0f));
|
|
|
|
|
|
|
|
// the default layout is left to right, typically used in languages
|
|
|
|
// originating from europe such as English, French, German, Spanish etc..
|
|
|
|
text->setLayout(osgText::Text::LEFT_TO_RIGHT);
|
|
|
|
|
|
|
|
text->setText("text->setLayout(osgText::Text::LEFT_TO_RIGHT);");
|
|
|
|
geode->addDrawable(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
osgText::Text* text = new osgText::Text;
|
|
|
|
text->setFont(font);
|
|
|
|
text->setColor(layoutColor);
|
|
|
|
text->setCharacterSize(layoutCharacterSize);
|
|
|
|
text->setPosition(osg::Vec3(windowWidth-margin,windowHeight-margin,0.0f));
|
|
|
|
|
|
|
|
// right to left layouts would be used for hebrew or arabic fonts.
|
|
|
|
text->setLayout(osgText::Text::RIGHT_TO_LEFT);
|
|
|
|
|
|
|
|
text->setText("text->setLayout(osgText::Text::RIGHT_TO_LEFT);");
|
|
|
|
geode->addDrawable(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
osgText::Text* text = new osgText::Text;
|
|
|
|
text->setFont(font);
|
|
|
|
text->setColor(layoutColor);
|
|
|
|
text->setPosition(osg::Vec3(margin,windowHeight-margin,0.0f));
|
|
|
|
text->setCharacterSize(layoutCharacterSize);
|
|
|
|
|
|
|
|
// vertical font layout would be used for asian fonts.
|
|
|
|
text->setLayout(osgText::Text::VERTICAL);
|
|
|
|
|
|
|
|
text->setText("text->setLayout(osgText::Text::VERTICAL);");
|
|
|
|
geode->addDrawable(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-05 20:28:42 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Examples of how to set up different font resolution
|
|
|
|
//
|
|
|
|
|
2003-03-05 01:14:42 +08:00
|
|
|
osg::Vec4 fontSizeColor(0.0f,1.0f,1.0f,1.0f);
|
|
|
|
float fontSizeCharacterSize = 30;
|
|
|
|
|
|
|
|
osg::Vec3 cursor = osg::Vec3(margin*2,windowHeight-margin*2,0.0f);
|
|
|
|
|
|
|
|
{
|
|
|
|
osgText::Text* text = new osgText::Text;
|
|
|
|
text->setFont(font);
|
|
|
|
text->setColor(fontSizeColor);
|
|
|
|
text->setCharacterSize(fontSizeCharacterSize);
|
|
|
|
text->setPosition(cursor);
|
|
|
|
|
|
|
|
// use text that uses 10 by 10 texels as a target resolution for fonts.
|
2003-04-30 19:40:17 +08:00
|
|
|
text->setFontResolution(10,10); // blocky but small texture memory usage
|
2003-03-05 01:14:42 +08:00
|
|
|
|
2003-04-30 19:40:17 +08:00
|
|
|
text->setText("text->setFontResolution(10,10); // blocky but small texture memory usage");
|
2003-03-05 01:14:42 +08:00
|
|
|
geode->addDrawable(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
cursor.y() -= fontSizeCharacterSize;
|
|
|
|
{
|
|
|
|
osgText::Text* text = new osgText::Text;
|
|
|
|
text->setFont(font);
|
|
|
|
text->setColor(fontSizeColor);
|
|
|
|
text->setCharacterSize(fontSizeCharacterSize);
|
|
|
|
text->setPosition(cursor);
|
|
|
|
|
|
|
|
// use text that uses 10 by 10 texels as a target resolution for fonts.
|
2003-04-30 19:40:17 +08:00
|
|
|
text->setFontResolution(20,20); // smoother but higher texture memory usage (but still quite low).
|
2003-03-05 01:14:42 +08:00
|
|
|
|
2003-04-30 19:40:17 +08:00
|
|
|
text->setText("text->setFontResolution(20,20); // smoother but higher texture memory usage (but still quite low).");
|
2003-03-05 01:14:42 +08:00
|
|
|
geode->addDrawable(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
cursor.y() -= fontSizeCharacterSize;
|
|
|
|
{
|
|
|
|
osgText::Text* text = new osgText::Text;
|
|
|
|
text->setFont(font);
|
|
|
|
text->setColor(fontSizeColor);
|
|
|
|
text->setCharacterSize(fontSizeCharacterSize);
|
|
|
|
text->setPosition(cursor);
|
|
|
|
|
|
|
|
// use text that uses 10 by 10 texels as a target resolution for fonts.
|
2003-04-30 19:40:17 +08:00
|
|
|
text->setFontResolution(40,40); // even smoother but again higher texture memory usage.
|
2003-03-05 01:14:42 +08:00
|
|
|
|
2003-04-30 19:40:17 +08:00
|
|
|
text->setText("text->setFontResolution(40,40); // even smoother but again higher texture memory usage.");
|
2003-03-05 01:14:42 +08:00
|
|
|
geode->addDrawable(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-05 20:28:42 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Examples of how to set up different sized text
|
|
|
|
//
|
|
|
|
|
2003-03-05 01:14:42 +08:00
|
|
|
osg::Vec4 characterSizeColor(1.0f,0.0f,1.0f,1.0f);
|
|
|
|
|
|
|
|
cursor.y() -= fontSizeCharacterSize*2.0f;
|
|
|
|
|
|
|
|
{
|
|
|
|
osgText::Text* text = new osgText::Text;
|
|
|
|
text->setFont(font);
|
|
|
|
text->setColor(characterSizeColor);
|
2003-04-30 19:40:17 +08:00
|
|
|
text->setFontResolution(20,20);
|
2003-03-05 01:14:42 +08:00
|
|
|
text->setPosition(cursor);
|
|
|
|
|
2003-03-05 17:08:11 +08:00
|
|
|
// use text that 20 units high.
|
|
|
|
text->setCharacterSize(20); // small
|
2003-03-05 01:14:42 +08:00
|
|
|
|
2003-03-05 17:08:11 +08:00
|
|
|
text->setText("text->setCharacterSize(15.0f); // small");
|
2003-03-05 01:14:42 +08:00
|
|
|
geode->addDrawable(text);
|
|
|
|
}
|
|
|
|
|
2003-03-05 17:08:11 +08:00
|
|
|
cursor.y() -= 30.0f;
|
2003-03-05 01:14:42 +08:00
|
|
|
{
|
|
|
|
osgText::Text* text = new osgText::Text;
|
|
|
|
text->setFont(font);
|
|
|
|
text->setColor(characterSizeColor);
|
2003-04-30 19:40:17 +08:00
|
|
|
text->setFontResolution(30,30);
|
2003-03-05 01:14:42 +08:00
|
|
|
text->setPosition(cursor);
|
|
|
|
|
2003-03-05 17:08:11 +08:00
|
|
|
// use text that 20 units high.
|
|
|
|
text->setCharacterSize(30.0f); // medium
|
2003-03-05 01:14:42 +08:00
|
|
|
|
2003-03-05 17:08:11 +08:00
|
|
|
text->setText("text->setCharacterSize(30.0f); // medium");
|
2003-03-05 01:14:42 +08:00
|
|
|
geode->addDrawable(text);
|
|
|
|
}
|
|
|
|
|
2003-03-05 17:08:11 +08:00
|
|
|
cursor.y() -= 50.0f;
|
2003-03-05 01:14:42 +08:00
|
|
|
{
|
|
|
|
osgText::Text* text = new osgText::Text;
|
|
|
|
text->setFont(font);
|
|
|
|
text->setColor(characterSizeColor);
|
2003-04-30 19:40:17 +08:00
|
|
|
text->setFontResolution(40,40);
|
2003-03-05 01:14:42 +08:00
|
|
|
text->setPosition(cursor);
|
|
|
|
|
|
|
|
// use text that uses 10 by 10 texels as a target resolution for fonts.
|
2003-03-05 17:08:11 +08:00
|
|
|
text->setCharacterSize(60.0f); // large
|
2003-03-05 01:14:42 +08:00
|
|
|
|
2003-03-05 17:08:11 +08:00
|
|
|
text->setText("text->setCharacterSize(60.0f); // large");
|
2003-03-05 01:14:42 +08:00
|
|
|
geode->addDrawable(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-05 20:28:42 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Examples of how to set up different alignments
|
|
|
|
//
|
2003-03-05 01:14:42 +08:00
|
|
|
|
2003-03-05 20:28:42 +08:00
|
|
|
osg::Vec4 alignmentSizeColor(0.0f,1.0f,0.0f,1.0f);
|
|
|
|
float alignmentCharacterSize = 25.0f;
|
|
|
|
cursor.x() = 640;
|
|
|
|
cursor.y() = margin*4.0f;
|
2003-02-21 22:05:39 +08:00
|
|
|
|
2003-03-05 20:28:42 +08:00
|
|
|
typedef std::pair<osgText::Text::AlignmentType,std::string> AlignmentPair;
|
|
|
|
typedef std::vector<AlignmentPair> AlignmentList;
|
|
|
|
AlignmentList alignmentList;
|
|
|
|
alignmentList.push_back(AlignmentPair(osgText::Text::LEFT_TOP,"text->setAlignment(osgText::Text::LEFT_TOP);"));
|
|
|
|
alignmentList.push_back(AlignmentPair(osgText::Text::LEFT_CENTER,"text->setAlignment(osgText::Text::LEFT_CENTER);"));
|
|
|
|
alignmentList.push_back(AlignmentPair(osgText::Text::LEFT_BOTTOM,"text->setAlignment(osgText::Text::LEFT_BOTTOM);"));
|
|
|
|
alignmentList.push_back(AlignmentPair(osgText::Text::CENTER_TOP,"text->setAlignment(osgText::Text::CENTER_TOP);"));
|
|
|
|
alignmentList.push_back(AlignmentPair(osgText::Text::CENTER_CENTER,"text->setAlignment(osgText::Text::CENTER_CENTER);"));
|
|
|
|
alignmentList.push_back(AlignmentPair(osgText::Text::CENTER_BOTTOM,"text->setAlignment(osgText::Text::CENTER_BOTTOM);"));
|
|
|
|
alignmentList.push_back(AlignmentPair(osgText::Text::RIGHT_TOP,"text->setAlignment(osgText::Text::RIGHT_TOP);"));
|
|
|
|
alignmentList.push_back(AlignmentPair(osgText::Text::RIGHT_CENTER,"text->setAlignment(osgText::Text::RIGHT_CENTER);"));
|
|
|
|
alignmentList.push_back(AlignmentPair(osgText::Text::RIGHT_BOTTOM,"text->setAlignment(osgText::Text::RIGHT_BOTTOM);"));
|
2003-04-28 19:37:53 +08:00
|
|
|
alignmentList.push_back(AlignmentPair(osgText::Text::LEFT_BASE_LINE,"text->setAlignment(osgText::Text::BASE_LINE);"));
|
|
|
|
alignmentList.push_back(AlignmentPair(osgText::Text::CENTER_BASE_LINE,"text->setAlignment(osgText::Text::CENTER_BASE_LINE);"));
|
|
|
|
alignmentList.push_back(AlignmentPair(osgText::Text::RIGHT_BASE_LINE,"text->setAlignment(osgText::Text::RIGHT_BASE_LINE);"));
|
2003-03-05 20:28:42 +08:00
|
|
|
|
|
|
|
osg::Sequence* sequence = new osg::Sequence;
|
2003-03-05 17:08:11 +08:00
|
|
|
{
|
2003-03-05 20:28:42 +08:00
|
|
|
for(AlignmentList::iterator itr=alignmentList.begin();
|
|
|
|
itr!=alignmentList.end();
|
|
|
|
++itr)
|
2003-03-05 17:08:11 +08:00
|
|
|
{
|
|
|
|
osg::Geode* alignmentGeode = new osg::Geode;
|
|
|
|
sequence->addChild(alignmentGeode);
|
2003-03-05 20:28:42 +08:00
|
|
|
sequence->setTime(sequence->getNumChildren(), 1.0f);
|
2003-03-05 17:08:11 +08:00
|
|
|
|
|
|
|
osgText::Text* text = new osgText::Text;
|
|
|
|
text->setFont(font);
|
2003-03-05 20:28:42 +08:00
|
|
|
text->setColor(alignmentSizeColor);
|
|
|
|
text->setCharacterSize(alignmentCharacterSize);
|
2003-03-05 17:08:11 +08:00
|
|
|
text->setPosition(cursor);
|
|
|
|
text->setDrawMode(osgText::Text::TEXT|osgText::Text::ALIGNMENT|osgText::Text::BOUNDINGBOX);
|
|
|
|
|
2003-03-05 20:28:42 +08:00
|
|
|
text->setAlignment(itr->first);
|
|
|
|
text->setText(itr->second);
|
2003-03-05 17:08:11 +08:00
|
|
|
|
|
|
|
alignmentGeode->addDrawable(text);
|
2003-02-21 22:05:39 +08:00
|
|
|
|
|
|
|
|
2003-03-05 17:08:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2003-03-05 20:28:42 +08:00
|
|
|
|
|
|
|
sequence->setMode(osg::Sequence::START);
|
|
|
|
sequence->setInterval(osg::Sequence::LOOP, 0, -1);
|
|
|
|
sequence->setDuration(1.0f, -1);
|
|
|
|
|
2003-03-05 17:08:11 +08:00
|
|
|
rootNode->addChild(sequence);
|
2003-03-05 20:28:42 +08:00
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Examples of how to set up different fonts...
|
|
|
|
//
|
|
|
|
|
|
|
|
cursor.x() = margin*2.0f;
|
|
|
|
cursor.y() = margin*2.0f;
|
|
|
|
|
|
|
|
osg::Vec4 fontColor(1.0f,0.5f,0.0f,1.0f);
|
|
|
|
float fontCharacterSize = 20.0f;
|
|
|
|
float spacing = 40.0f;
|
|
|
|
|
|
|
|
{
|
|
|
|
osgText::Text* text = new osgText::Text;
|
|
|
|
text->setColor(fontColor);
|
|
|
|
text->setPosition(cursor);
|
|
|
|
text->setCharacterSize(fontCharacterSize);
|
|
|
|
|
|
|
|
text->setFont(0);
|
|
|
|
text->setText("text->setFont(0); // inbuilt font.");
|
|
|
|
geode->addDrawable(text);
|
|
|
|
|
|
|
|
cursor.x() = text->getBound().xMax() + spacing ;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
osgText::Font* arial = osgText::readFontFile("fonts/arial.ttf");
|
|
|
|
|
|
|
|
osgText::Text* text = new osgText::Text;
|
|
|
|
text->setColor(fontColor);
|
|
|
|
text->setPosition(cursor);
|
|
|
|
text->setCharacterSize(fontCharacterSize);
|
|
|
|
|
|
|
|
text->setFont(arial);
|
|
|
|
text->setText(arial!=0?
|
|
|
|
"text->setFont(\"fonts/arial.ttf\");":
|
|
|
|
"unable to load \"fonts/arial.ttf\"");
|
|
|
|
geode->addDrawable(text);
|
|
|
|
|
|
|
|
cursor.x() = text->getBound().xMax() + spacing ;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
osgText::Font* times = osgText::readFontFile("fonts/times.ttf");
|
|
|
|
|
|
|
|
osgText::Text* text = new osgText::Text;
|
|
|
|
text->setColor(fontColor);
|
|
|
|
text->setPosition(cursor);
|
|
|
|
text->setCharacterSize(fontCharacterSize);
|
|
|
|
|
|
|
|
geode->addDrawable(text);
|
|
|
|
text->setFont(times);
|
|
|
|
text->setText(times!=0?
|
|
|
|
"text->setFont(\"fonts/times.ttf\");":
|
|
|
|
"unable to load \"fonts/times.ttf\"");
|
|
|
|
|
|
|
|
cursor.x() = text->getBound().xMax() + spacing ;
|
|
|
|
}
|
|
|
|
|
|
|
|
cursor.x() = margin*2.0f;
|
|
|
|
cursor.y() = margin;
|
|
|
|
|
|
|
|
{
|
|
|
|
osgText::Font* dirtydoz = osgText::readFontFile("fonts/dirtydoz.ttf");
|
|
|
|
|
|
|
|
osgText::Text* text = new osgText::Text;
|
|
|
|
text->setColor(fontColor);
|
|
|
|
text->setPosition(cursor);
|
|
|
|
text->setCharacterSize(fontCharacterSize);
|
|
|
|
|
|
|
|
text->setFont(dirtydoz);
|
|
|
|
text->setText(dirtydoz!=0?
|
|
|
|
"text->setFont(\"fonts/dirtydoz.ttf\");":
|
|
|
|
"unable to load \"fonts/dirtydoz.ttf\"");
|
|
|
|
geode->addDrawable(text);
|
|
|
|
|
|
|
|
cursor.x() = text->getBound().xMax() + spacing ;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
osgText::Font* fudd = osgText::readFontFile("fonts/fudd.ttf");
|
|
|
|
|
|
|
|
osgText::Text* text = new osgText::Text;
|
|
|
|
text->setColor(fontColor);
|
|
|
|
text->setPosition(cursor);
|
|
|
|
text->setCharacterSize(fontCharacterSize);
|
|
|
|
|
|
|
|
text->setFont(fudd);
|
|
|
|
text->setText(fudd!=0?
|
|
|
|
"text->setFont(\"fonts/fudd.ttf\");":
|
|
|
|
"unable to load \"fonts/fudd.ttf\"");
|
|
|
|
geode->addDrawable(text);
|
|
|
|
|
|
|
|
cursor.x() = text->getBound().xMax() + spacing ;
|
|
|
|
}
|
2003-03-05 17:08:11 +08:00
|
|
|
|
2003-03-03 05:05:05 +08:00
|
|
|
return rootNode;
|
|
|
|
}
|
2003-02-21 22:05:39 +08:00
|
|
|
|
2003-03-05 20:28:42 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// create text which sits in 3D space such as would be inserted into a normal model
|
|
|
|
osg::Group* create3DText(const osg::Vec3& center,float radius)
|
2003-03-03 05:05:05 +08:00
|
|
|
{
|
2003-02-21 22:05:39 +08:00
|
|
|
|
2003-03-03 05:05:05 +08:00
|
|
|
osg::Geode* geode = new osg::Geode;
|
|
|
|
|
2003-03-05 20:28:42 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Examples of how to set up axis/orientation alignments
|
|
|
|
//
|
|
|
|
|
|
|
|
float characterSize=radius*0.2f;
|
|
|
|
|
|
|
|
osg::Vec3 pos(center.x()-radius*.5f,center.y()-radius*.5f,center.z()-radius*.5f);
|
|
|
|
|
2003-03-03 05:05:05 +08:00
|
|
|
osgText::Text* text1 = new osgText::Text;
|
|
|
|
text1->setFont("fonts/times.ttf");
|
2003-03-05 20:28:42 +08:00
|
|
|
text1->setCharacterSize(characterSize);
|
|
|
|
text1->setPosition(pos);
|
2003-03-03 05:05:05 +08:00
|
|
|
text1->setAxisAlignment(osgText::Text::XY_PLANE);
|
|
|
|
text1->setText("XY_PLANE");
|
|
|
|
geode->addDrawable(text1);
|
|
|
|
|
|
|
|
osgText::Text* text2 = new osgText::Text;
|
|
|
|
text2->setFont("fonts/times.ttf");
|
2003-03-05 20:28:42 +08:00
|
|
|
text2->setCharacterSize(characterSize);
|
|
|
|
text2->setPosition(pos);
|
2003-03-03 05:05:05 +08:00
|
|
|
text2->setAxisAlignment(osgText::Text::YZ_PLANE);
|
|
|
|
text2->setText("YZ_PLANE");
|
|
|
|
geode->addDrawable(text2);
|
|
|
|
|
|
|
|
osgText::Text* text3 = new osgText::Text;
|
|
|
|
text3->setFont("fonts/times.ttf");
|
2003-03-05 20:28:42 +08:00
|
|
|
text3->setCharacterSize(characterSize);
|
|
|
|
text3->setPosition(pos);
|
2003-03-03 05:05:05 +08:00
|
|
|
text3->setAxisAlignment(osgText::Text::XZ_PLANE);
|
|
|
|
text3->setText("XZ_PLANE");
|
|
|
|
geode->addDrawable(text3);
|
|
|
|
|
2003-03-05 17:08:11 +08:00
|
|
|
|
2003-03-03 05:05:05 +08:00
|
|
|
osgText::Text* text4 = new osgText::Text;
|
|
|
|
text4->setFont("fonts/times.ttf");
|
2003-03-05 20:28:42 +08:00
|
|
|
text4->setCharacterSize(characterSize);
|
|
|
|
text4->setPosition(center);
|
2003-03-03 05:05:05 +08:00
|
|
|
text4->setAxisAlignment(osgText::Text::SCREEN);
|
|
|
|
text4->setText("SCREEN");
|
|
|
|
geode->addDrawable(text4);
|
2003-02-21 22:05:39 +08:00
|
|
|
|
2003-03-05 20:28:42 +08:00
|
|
|
osg::ShapeDrawable* shape = new osg::ShapeDrawable(new osg::Sphere(center,characterSize*0.2f));
|
2003-03-05 17:08:11 +08:00
|
|
|
shape->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::ON);
|
|
|
|
geode->addDrawable(shape);
|
|
|
|
|
|
|
|
|
2003-03-03 05:05:05 +08:00
|
|
|
osg::Group* rootNode = new osg::Group;
|
2003-02-21 22:05:39 +08:00
|
|
|
rootNode->addChild(geode);
|
|
|
|
|
|
|
|
return rootNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main( int argc, char **argv )
|
|
|
|
{
|
|
|
|
// use an ArgumentParser object to manage the program arguments.
|
|
|
|
osg::ArgumentParser arguments(&argc,argv);
|
|
|
|
|
|
|
|
// set up the usage document, in case we need to print out how to use this program.
|
2003-04-09 19:44:32 +08:00
|
|
|
arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the example which demonstrates use of text.");
|
2003-04-07 05:32:44 +08:00
|
|
|
arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] [filename] ...");
|
2003-02-21 22:05:39 +08:00
|
|
|
arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information");
|
|
|
|
|
|
|
|
|
|
|
|
// construct the viewer.
|
|
|
|
osgProducer::Viewer viewer(arguments);
|
|
|
|
|
|
|
|
// set up the value with sensible default event handlers.
|
|
|
|
viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS);
|
|
|
|
|
|
|
|
// get details on keyboard and mouse bindings used by the viewer.
|
|
|
|
viewer.getUsage(*arguments.getApplicationUsage());
|
|
|
|
|
|
|
|
// if user request help write it out to cout.
|
|
|
|
if (arguments.read("-h") || arguments.read("--help"))
|
|
|
|
{
|
2003-03-05 03:52:32 +08:00
|
|
|
arguments.getApplicationUsage()->write(std::cout);
|
2003-02-21 22:05:39 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// any option left unread are converted into errors to write out later.
|
|
|
|
arguments.reportRemainingOptionsAsUnrecognized();
|
|
|
|
|
|
|
|
// report any errors if they have occured when parsing the program aguments.
|
|
|
|
if (arguments.errors())
|
|
|
|
{
|
2003-03-05 03:52:32 +08:00
|
|
|
arguments.writeErrorMessages(std::cout);
|
2003-02-21 22:05:39 +08:00
|
|
|
return 1;
|
|
|
|
}
|
2003-04-07 05:32:44 +08:00
|
|
|
|
2003-02-21 22:05:39 +08:00
|
|
|
|
|
|
|
// read the scene from the list of file specified commandline args.
|
|
|
|
osg::ref_ptr<osg::Node> rootNode = osgDB::readNodeFiles(arguments);
|
|
|
|
|
|
|
|
// prepare scene.
|
|
|
|
{
|
|
|
|
|
2003-03-05 20:28:42 +08:00
|
|
|
osg::Vec3 center(0.0f,0.0f,0.0f);
|
|
|
|
float radius = 1.0f;
|
|
|
|
|
2003-02-21 22:05:39 +08:00
|
|
|
if (rootNode.valid())
|
|
|
|
{
|
|
|
|
// optimize the scene graph, remove rendundent nodes and state etc.
|
|
|
|
osgUtil::Optimizer optimizer;
|
|
|
|
optimizer.optimize(rootNode.get());
|
2003-03-05 20:28:42 +08:00
|
|
|
|
|
|
|
const osg::BoundingSphere& bs = rootNode->getBound();
|
|
|
|
center = bs.center();
|
|
|
|
radius = bs.radius();
|
2003-02-21 22:05:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// make sure the root node is group so we can add extra nodes to it.
|
|
|
|
osg::Group* group = dynamic_cast<osg::Group*>(rootNode.get());
|
|
|
|
if (!group)
|
|
|
|
{
|
|
|
|
group = new osg::Group;
|
|
|
|
|
|
|
|
if (rootNode.valid()) group->addChild(rootNode.get());
|
|
|
|
|
|
|
|
rootNode = group;
|
|
|
|
}
|
|
|
|
|
2003-03-03 05:05:05 +08:00
|
|
|
{
|
|
|
|
// create the hud.
|
|
|
|
osg::Projection* projection = new osg::Projection;
|
|
|
|
projection->setMatrix(osg::Matrix::ortho2D(0,1280,0,1024));
|
|
|
|
|
|
|
|
osg::MatrixTransform* modelview_abs = new osg::MatrixTransform;
|
|
|
|
modelview_abs->setReferenceFrame(osg::Transform::RELATIVE_TO_ABSOLUTE);
|
|
|
|
modelview_abs->setMatrix(osg::Matrix::identity());
|
2003-02-21 22:05:39 +08:00
|
|
|
|
2003-03-03 05:05:05 +08:00
|
|
|
modelview_abs->addChild(createHUDText());
|
2003-02-21 22:05:39 +08:00
|
|
|
|
2003-03-03 05:05:05 +08:00
|
|
|
projection->addChild(modelview_abs);
|
2003-02-21 22:05:39 +08:00
|
|
|
|
2003-03-03 05:05:05 +08:00
|
|
|
group->addChild(projection);
|
|
|
|
}
|
2003-02-21 22:05:39 +08:00
|
|
|
|
2003-03-05 20:28:42 +08:00
|
|
|
group->addChild(create3DText(center,radius));
|
2003-02-21 22:05:39 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// set the scene to render
|
|
|
|
viewer.setSceneData(rootNode.get());
|
2003-03-05 17:08:11 +08:00
|
|
|
|
2003-04-10 21:41:45 +08:00
|
|
|
|
2003-02-21 22:05:39 +08:00
|
|
|
// create the windows and run the threads.
|
2003-04-08 23:18:45 +08:00
|
|
|
viewer.realize();
|
2003-02-21 22:05:39 +08:00
|
|
|
|
2003-04-10 21:41:45 +08:00
|
|
|
#if 0
|
|
|
|
// this optional compile block is done as a test against graphics
|
|
|
|
// drivers that claim support for generate mip map, but the actual
|
|
|
|
// implementation is flacky. It is not compiled by default.
|
|
|
|
|
|
|
|
// go through each graphics context and switch off the generate mip map extension.
|
|
|
|
// note, this must be done after the realize so that init of texture state and as
|
|
|
|
// result extension structures have been iniatilized.
|
|
|
|
for(unsigned int contextID = 0;
|
|
|
|
contextID<viewer.getDisplaySettings()->getMaxNumberOfGraphicsContexts();
|
|
|
|
++contextID)
|
|
|
|
{
|
|
|
|
osg::Texture::Extensions* textureExt = osg::Texture::getExtensions(contextID,false);
|
|
|
|
if (textureExt) textureExt->setGenerateMipMapSupported(false);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2003-02-21 22:05:39 +08:00
|
|
|
while( !viewer.done() )
|
|
|
|
{
|
|
|
|
// wait for all cull and draw threads to complete.
|
|
|
|
viewer.sync();
|
|
|
|
|
|
|
|
// update the scene by traversing it with the the update visitor which will
|
|
|
|
// call all node update callbacks and animations.
|
|
|
|
viewer.update();
|
|
|
|
|
|
|
|
// fire off the cull and draw traversals of the scene.
|
|
|
|
viewer.frame();
|
|
|
|
|
|
|
|
}
|
2003-03-25 18:05:09 +08:00
|
|
|
|
|
|
|
// wait for all cull and draw threads to complete before exit.
|
|
|
|
viewer.sync();
|
2003-03-04 20:34:42 +08:00
|
|
|
|
2003-02-21 22:05:39 +08:00
|
|
|
return 0;
|
|
|
|
}
|