Renamed osgText::Font::SizePair to osgText::FontSizePair in prep for use this more

widely within osgText/freetype plugin.

Added support for inserting loading models into --mt multithreaded implementation.
This commit is contained in:
Robert Osfield 2007-12-23 13:18:40 +00:00
parent 8c5a9ac218
commit dea067050c
5 changed files with 33 additions and 14 deletions

View File

@ -481,8 +481,10 @@ class UpdateTextOperation : public osg::Operation
{
public:
UpdateTextOperation(osg::Group* group):
UpdateTextOperation(const osg::Vec3& center, float diameter, osg::Group* group):
Operation("UpdateTextOperation", true),
_center(center),
_diameter(diameter),
_maxNumChildren(200),
_maxNumTextPerGeode(10),
_group(group)
@ -544,7 +546,7 @@ public:
for(unsigned int i=0; i<_maxNumTextPerGeode; ++i)
{
osg::Vec3 position(float(rand()) / float(RAND_MAX), float(rand()) / float(RAND_MAX), float(i)/float(_maxNumTextPerGeode));
osg::Vec3 position(float(rand()) / float(RAND_MAX) - 0.5f, float(rand()) / float(RAND_MAX) - 0.5f, float(i)/float(_maxNumTextPerGeode) - 0.5f);
std::string str;
unsigned int _numCharacters = 5;
@ -555,10 +557,10 @@ public:
osgText::Text* text = new osgText::Text;
text->setDataVariance(osg::Object::DYNAMIC);
text->setPosition(position);
text->setPosition(_center + position * _diameter);
text->setFont("times.ttf");
text->setText(str);
text->setCharacterSize(0.025f);
text->setCharacterSize(0.025f * _diameter);
text->setAxisAlignment(osgText::Text::SCREEN);
geode->addDrawable(text);
@ -583,6 +585,8 @@ public:
typedef std::list< osg::ref_ptr<osg::Geode> > AvailableList;
osg::Vec3 _center;
float _diameter;
unsigned int _maxNumChildren;
unsigned int _maxNumTextPerGeode;
@ -618,6 +622,18 @@ int main(int argc, char** argv)
// create a group to add everything into.
osg::Group* mainGroup = new osg::Group;
osg::Vec3 center(0.5f,0.5f,0.5f);
float diameter = 1.0f;
osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments);
if (loadedModel.valid())
{
mainGroup->addChild(loadedModel.get());
center = loadedModel->getBound().center();
diameter = loadedModel->getBound().radius() * 2.0f;
}
for(unsigned int i=0; i<numThreads; ++i)
{
osg::Group* textGroup = new osg::Group;
@ -630,7 +646,7 @@ int main(int argc, char** argv)
// create the operation that will run in the background and
// sync once per frame with the main viewer loop.
updateOperation = new UpdateTextOperation(textGroup);
updateOperation = new UpdateTextOperation(center, diameter, textGroup);
// add the operation to the operation thread and start it.
operationThread->add(updateOperation.get());
@ -643,7 +659,7 @@ int main(int argc, char** argv)
// add a unit cube for the text to appear within.
osg::Geode* geode = new osg::Geode;
geode->getOrCreateStateSet()->setAttribute(new osg::PolygonMode(osg::PolygonMode::FRONT_AND_BACK,osg::PolygonMode::LINE));
geode->addDrawable(new osg::ShapeDrawable(new osg::Box(osg::Vec3(0.5f,0.5f,0.5f),1.0)));
geode->addDrawable(new osg::ShapeDrawable(new osg::Box(center,diameter)));
mainGroup->addChild(geode);
}

View File

@ -24,6 +24,7 @@
#include <osg/buffered_value>
#include <osg/TexEnv>
#include <osgDB/ReaderWriter>
#include <osgText/Export>
#include <osgText/KerningType>
@ -34,7 +35,6 @@ namespace osgText {
class Font;
class Text;
/** Read a font from specified file. The filename may contain a path.
* It will search for the font file in the following places in this order:
* - In the current directory
@ -176,12 +176,11 @@ protected:
typedef std::vector< osg::ref_ptr<osg::StateSet> > StateSetList;
typedef std::map< unsigned int, osg::ref_ptr<Glyph> > GlyphMap;
typedef std::pair< unsigned int, unsigned int > SizePair;
typedef std::map< SizePair, GlyphMap > SizeGlyphMap;
typedef std::map< FontSizePair, GlyphMap > FontSizeGlyphMap;
osg::ref_ptr<osg::TexEnv> _texenv;
osg::ref_ptr<osg::StateSet> _stateset;
SizeGlyphMap _sizeGlyphMap;
FontSizeGlyphMap _sizeGlyphMap;
GlyphTextureList _glyphTextureList;
// current active size of font

View File

@ -16,11 +16,15 @@
namespace osgText
{
typedef std::pair< unsigned int, unsigned int > FontSizePair;
enum KerningType
{
KERNING_DEFAULT, //default locked to integer kerning values
KERNING_UNFITTED, //use floating point value for kerning
KERNING_NONE //no kerning
};
}
#endif /*OSGTEXT_KERNINGTYPE*/

View File

@ -52,14 +52,14 @@ Font::Glyph* DefaultFont::getGlyph(unsigned int charcode)
{
if (_sizeGlyphMap.empty()) return 0;
SizeGlyphMap::iterator itr = _sizeGlyphMap.find(SizePair(_width,_height));
FontSizeGlyphMap::iterator itr = _sizeGlyphMap.find(FontSizePair(_width,_height));
if (itr==_sizeGlyphMap.end())
{
// no font found of correct size, will need to find the nearest.
itr = _sizeGlyphMap.begin();
int mindeviation = abs((int)_width-(int)itr->first.first)+
abs((int)_height-(int)itr->first.second);
SizeGlyphMap::iterator sitr=itr;
FontSizeGlyphMap::iterator sitr=itr;
++sitr;
for(;
sitr!=_sizeGlyphMap.end();

View File

@ -347,7 +347,7 @@ osg::Texture::FilterMode Font::getMagFilterHint() const
Font::Glyph* Font::getGlyph(unsigned int charcode)
{
SizeGlyphMap::iterator itr = _sizeGlyphMap.find(SizePair(_width,_height));
FontSizeGlyphMap::iterator itr = _sizeGlyphMap.find(FontSizePair(_width,_height));
if (itr!=_sizeGlyphMap.end())
{
GlyphMap& glyphmap = itr->second;
@ -417,7 +417,7 @@ bool Font::hasVertical() const
void Font::addGlyph(unsigned int width, unsigned int height, unsigned int charcode, Glyph* glyph)
{
_sizeGlyphMap[SizePair(width,height)][charcode]=glyph;
_sizeGlyphMap[FontSizePair(width,height)][charcode]=glyph;
int posX=0,posY=0;