support for font textures. They are normal (but rather lenghty) <material>,

but contain <glyph> entries with <name>, <left> and <right>. The latter two
describe where in the texture a letter or symbol begins and where it ends.
(range 0-1). <xscale> defines a horizontal scaling factor.
This commit is contained in:
mfranz
2006-04-09 19:21:13 +00:00
parent 76c6482495
commit 509a388ccc
2 changed files with 59 additions and 0 deletions

View File

@@ -159,6 +159,15 @@ SGMaterial::read_properties( const string &fg_root, const SGPropertyNode * props
((SGPropertyNode *)props)->getChildren("object-group");
for (unsigned int i = 0; i < object_group_nodes.size(); i++)
object_groups.push_back(new SGMatModelGroup(object_group_nodes[i]));
// handling of glyphs for taxi-/runway-signs
xscale = props->getDoubleValue("xscale", 1.0);
vector<SGPropertyNode_ptr> glyph_nodes = props->getChildren("glyph");
for (unsigned int i = 0; i < glyph_nodes.size(); i++) {
const char *name = glyph_nodes[i]->getStringValue("name");
if (name)
glyphs[name] = new SGMaterialGlyph(glyph_nodes[i]);
}
}
@@ -176,6 +185,8 @@ SGMaterial::init ()
ysize = 0;
wrapu = true;
wrapv = true;
xscale = 1;
mipmap = true;
light_coverage = 0.0;
shininess = 1.0;
@@ -276,4 +287,17 @@ void SGMaterial::set_ssg_state( ssgSimpleState *s )
_status.push_back( _internal_state( s, "", true ) );
}
////////////////////////////////////////////////////////////////////////
// SGMaterialGlyph.
////////////////////////////////////////////////////////////////////////
SGMaterialGlyph::SGMaterialGlyph(SGPropertyNode *p) :
_left(p->getDoubleValue("left", 0.0)),
_right(p->getDoubleValue("right", 1.0))
{
}
// end of mat.cxx

View File

@@ -34,6 +34,7 @@
#include STL_STRING // Standard C++ string library
#include <vector>
#include <map>
#include <plib/sg.h>
#include <plib/ssg.h>
@@ -46,6 +47,10 @@
SG_USING_STD(string);
SG_USING_STD(vector);
SG_USING_STD(map);
class SGMaterialGlyph;
/**
@@ -163,6 +168,19 @@ public:
return object_groups[index];
}
/**
* Get the horizontal scaling factor for runway/taxiway signs.
*/
virtual inline double get_xscale() const { return xscale; }
/**
* Return pointer to glyph class, or 0 if it doesn't exist.
*/
virtual SGMaterialGlyph * get_glyph (const string& name) const {
map<string, SGMaterialGlyph *>::const_iterator it = glyphs.find(name);
return it != glyphs.end() ? it->second : 0;
}
protected:
@@ -216,6 +234,10 @@ private:
vector<SGSharedPtr<SGMatModelGroup> > object_groups;
// taxiway-/runway-sign elements
double xscale;
map<string, SGMaterialGlyph *> glyphs;
////////////////////////////////////////////////////////////////////
// Internal constructors and methods.
@@ -230,4 +252,17 @@ private:
};
class SGMaterialGlyph {
public:
SGMaterialGlyph(SGPropertyNode *);
inline double get_left() const { return _left; }
inline double get_right() const { return _right; }
inline double get_width() const { return _right - _left; }
protected:
double _left;
double _right;
};
#endif // _SG_MAT_HXX