]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/tgdb/apt_signs.cxx
Merge branch 'jmt/ref_ptr-conv'
[simgear.git] / simgear / scene / tgdb / apt_signs.cxx
index 83529475731634bd116ba849b18ed231357b683e..d76622a6c397f9fec1752e9d666fca12a325da99 100644 (file)
@@ -106,6 +106,10 @@ SGMakeSign(SGMaterialLib *matlib, const string& path, const string& content)
     osg::Group* object = new osg::Group;
     object->setName(content);
 
+    SGMaterial *material = 0;
+    Effect *lighted_state = 0;
+    Effect *unlighted_state = 0;
+
     // Part I: parse & measure
     for (const char *s = content.data(); *s; s++) {
         string name;
@@ -215,31 +219,32 @@ SGMakeSign(SGMaterialLib *matlib, const string& path, const string& content)
             }
         }
 
-
-        if (newmat.size() == 0 )
-          continue;
-
-        SGMaterial *material = matlib->find(newmat);
-        if (!material) {
-            SG_LOG(SG_TERRAIN, SG_ALERT, SIGN "ignoring unknown material `" << newmat << '\'');
-            continue;
-        }
-
-
-        // set material states (lighted & unlighted)
-        Effect *lighted_state = material->get_effect();
-        Effect *unlighted_state;
-        string u = newmat + ".unlighted";
-
-        SGMaterial *m = matlib->find(u);
-        if (m) {
-            unlighted_state = m->get_effect();
-        } else {
-            SG_LOG(SG_TERRAIN, SG_ALERT, SIGN "ignoring unknown material `" << u << '\'');
-            unlighted_state = lighted_state;
+        if (newmat.size()) {
+            SGMaterial *m = matlib->find(newmat);
+            if (!m) {
+                // log error, but keep using previous material to at least show something
+                SG_LOG(SG_TERRAIN, SG_ALERT, SIGN "ignoring unknown material `" << newmat << '\'');
+            } else {
+                material = m;
+                // set material states (lighted & unlighted)
+                lighted_state = material->get_effect();
+                newmat.append(".unlighted");
+
+                m = matlib->find(newmat);
+                if (m) {
+                    unlighted_state = m->get_effect();
+                } else {
+                    SG_LOG(SG_TERRAIN, SG_ALERT, SIGN "ignoring unknown material `" << newmat << '\'');
+                    unlighted_state = lighted_state;
+                }
+            }
+            newmat.clear();
         }
-        newmat = "";
 
+        // This can only happen if the default material is missing.
+        // Error has been already logged in the block above.
+        if (!material) continue;
         SGMaterialGlyph *glyph = material->get_glyph(name);
         if (!glyph) {
             SG_LOG( SG_TERRAIN, SG_ALERT, SIGN "unsupported glyph `" << *s << '\'');
@@ -339,13 +344,20 @@ SGMakeSign(SGMaterialLib *matlib, const string& path, const string& content)
     vl->push_back(osg::Vec3(0, hpos,               dist + sign_height));
     vl->push_back(osg::Vec3(0, hpos - total_width, dist + sign_height));
 
+    osg::Vec2Array* tl = new osg::Vec2Array;
+    for (int i = 0; i < 4; ++i)
+        tl->push_back(osg::Vec2(0.0, 0.0));
     osg::Vec3Array* nl = new osg::Vec3Array;
     nl->push_back(osg::Vec3(0, 1, 0));
-
+    osg::Vec4Array* cl = new osg::Vec4Array;
+    cl->push_back(osg::Vec4(0.0, 0.0, 0.0, 1.0));
     osg::Geometry* geometry = new osg::Geometry;
     geometry->setVertexArray(vl);
     geometry->setNormalArray(nl);
     geometry->setNormalBinding(osg::Geometry::BIND_OVERALL);
+    geometry->setTexCoordArray(0, tl);
+    geometry->setColorArray(cl);
+    geometry->setColorBinding(osg::Geometry::BIND_OVERALL);
     geometry->addPrimitiveSet(new osg::DrawArrays(GL_TRIANGLE_STRIP, 0, vl->size()));
     EffectGeode* geode = new EffectGeode;
     geode->addDrawable(geometry);