]> git.mxchange.org Git - flightgear.git/blobdiff - src/Cockpit/panel.cxx
Set the key SGModelLib callback to make aircraft-dir OSG loading work.
[flightgear.git] / src / Cockpit / panel.cxx
index b0f6db745a2f159c466a1081cd9a88b6dbffe70f..9c39626ee6bd1dd4250047400a198064a1169b36 100644 (file)
 #  include <config.h>
 #endif
 
-#ifdef HAVE_WINDOWS_H          
-#  include <windows.h>
-#endif
+#include "panel.hxx"
 
 #include <stdio.h>     // sprintf
 #include <string.h>
+#include <iostream>
 
 #include <osg/CullFace>
 #include <osg/Depth>
 
 #include <simgear/compiler.h>
 
-#include SG_GLU_H
-
 #include <plib/fnt.h>
 
 #include <simgear/debug/logstream.hxx>
 #include <simgear/misc/sg_path.hxx>
 #include <simgear/scene/model/model.hxx>
+#include <osg/GLU>
 
 #include <Main/globals.hxx>
 #include <Main/fg_props.hxx>
 #include <Main/viewmgr.hxx>
 #include <Time/light.hxx>
 #include <GUI/new_gui.hxx>     // FGFontCache
+#include <Main/viewer.hxx>
+#include <Instrumentation/dclgps.hxx>
 
 #include "hud.hxx"
-#include "panel.hxx"
+
 
 #define WIN_X 0
 #define WIN_Y 0
@@ -98,18 +98,18 @@ get_aspect_adjust (int xsize, int ysize)
 bool
 fgPanelVisible ()
 {
-     if (globals->get_current_panel() == 0)
+     const FGPanel* current = globals->get_current_panel();
+     if (current == 0)
        return false;
-     if (globals->get_current_panel()->getVisibility() == 0)
+     if (current->getVisibility() == 0)
        return false;
      if (globals->get_viewmgr()->get_current() != 0)
        return false;
-     if (globals->get_current_view()->getHeadingOffset_deg() * SGD_DEGREES_TO_RADIANS != 0)
+     if (current->getAutohide() && globals->get_current_view()->getHeadingOffset_deg() * SGD_DEGREES_TO_RADIANS != 0)
        return false;
      return true;
 }
 
-
 \f
 ////////////////////////////////////////////////////////////////////////
 // Implementation of FGTextureManager.
@@ -118,16 +118,12 @@ fgPanelVisible ()
 map<string,osg::ref_ptr<osg::Texture2D> > FGTextureManager::_textureMap;
 
 osg::Texture2D*
-FGTextureManager::createTexture (const string &relativePath)
+FGTextureManager::createTexture (const string &relativePath, bool staticTexture)
 {
   osg::Texture2D* texture = _textureMap[relativePath].get();
   if (texture == 0) {
-    SG_LOG( SG_COCKPIT, SG_DEBUG,
-            "Texture " << relativePath << " does not yet exist" );
-    SGPath tpath(globals->get_fg_root());
-    tpath.append(relativePath);
-
-    texture = SGLoadTexture2D(tpath);
+    SGPath tpath = globals->resolve_aircraft_path(relativePath);
+    texture = SGLoadTexture2D(staticTexture, tpath);
 
     _textureMap[relativePath] = texture;
     if (!_textureMap[relativePath].valid()) 
@@ -139,7 +135,11 @@ FGTextureManager::createTexture (const string &relativePath)
 }
 
 
-
+void FGTextureManager::addTexture(const string &relativePath,
+                                  osg::Texture2D* texture)
+{
+    _textureMap[relativePath] = texture;
+}
 \f
 ////////////////////////////////////////////////////////////////////////
 // Implementation of FGCropped Texture.
@@ -368,19 +368,21 @@ FGPanel::draw(osg::State& state)
     material->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4(0, 0, 0, 1));
     material->setEmission(osg::Material::FRONT_AND_BACK, osg::Vec4(0, 0, 0, 1));
     panelStateSet->setAttribute(material);
-    panelStateSet->setMode(GL_COLOR_MATERIAL, osg::StateAttribute::ON);
     panelStateSet->setMode(GL_CULL_FACE, osg::StateAttribute::ON);
     panelStateSet->setAttributeAndModes(new osg::CullFace(osg::CullFace::BACK));
-    if ( _enable_depth_test )
-      panelStateSet->setAttributeAndModes(new osg::Depth(osg::Depth::ALWAYS));
-    else
-      panelStateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF);
+    panelStateSet->setAttributeAndModes(new osg::Depth(osg::Depth::LEQUAL));
   }
+  if ( _enable_depth_test )
+    panelStateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::ON);
+  else
+    panelStateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF);
   state.pushStateSet(panelStateSet.get());
   state.apply();
+  state.setActiveTextureUnit(0);
+  state.setClientActiveTextureUnit(0);
 
   FGLight *l = (FGLight *)(globals->get_subsystem("lighting"));
-  sgCopyVec4( panel_color, l->scene_diffuse());
+  sgCopyVec4( panel_color, l->scene_diffuse().data());
   if ( fgGetDouble("/systems/electrical/outputs/instrument-lights") > 1.0 ) {
       if ( panel_color[0] < 0.7 ) panel_color[0] = 0.7;
       if ( panel_color[1] < 0.2 ) panel_color[1] = 0.2;
@@ -390,6 +392,9 @@ FGPanel::draw(osg::State& state)
   if (_bg != 0) {
     state.pushStateSet(_bg.get());
     state.apply();
+    state.setActiveTextureUnit(0);
+    state.setClientActiveTextureUnit(0);
+
     glBegin(GL_POLYGON);
     glTexCoord2f(0.0, 0.0); glVertex2f(WIN_X, WIN_Y);
     glTexCoord2f(1.0, 0.0); glVertex2f(WIN_X + _width, WIN_Y);
@@ -398,11 +403,17 @@ FGPanel::draw(osg::State& state)
     glEnd();
     state.popStateSet();
     state.apply();
+    state.setActiveTextureUnit(0);
+    state.setClientActiveTextureUnit(0);
+
   } else {
     for (int i = 0; i < 4; i ++) {
       // top row of textures...(1,3,5,7)
       state.pushStateSet(_mbg[i*2].get());
       state.apply();
+      state.setActiveTextureUnit(0);
+      state.setClientActiveTextureUnit(0);
+
       glBegin(GL_POLYGON);
       glTexCoord2f(0.0, 0.0); glVertex2f(WIN_X + (_width/4) * i, WIN_Y + (_height/2));
       glTexCoord2f(1.0, 0.0); glVertex2f(WIN_X + (_width/4) * (i+1), WIN_Y + (_height/2));
@@ -411,9 +422,15 @@ FGPanel::draw(osg::State& state)
       glEnd();
       state.popStateSet();
       state.apply();
+      state.setActiveTextureUnit(0);
+      state.setClientActiveTextureUnit(0);
+
       // bottom row of textures...(2,4,6,8)
       state.pushStateSet(_mbg[i*2+1].get());
       state.apply();
+      state.setActiveTextureUnit(0);
+      state.setClientActiveTextureUnit(0);
+
       glBegin(GL_POLYGON);
       glTexCoord2f(0.0, 0.0); glVertex2f(WIN_X + (_width/4) * i, WIN_Y);
       glTexCoord2f(1.0, 0.0); glVertex2f(WIN_X + (_width/4) * (i+1), WIN_Y);
@@ -422,6 +439,9 @@ FGPanel::draw(osg::State& state)
       glEnd();
       state.popStateSet();
       state.apply();
+      state.setActiveTextureUnit(0);
+      state.setClientActiveTextureUnit(0);
+
     }
   }
 
@@ -467,21 +487,40 @@ FGPanel::draw(osg::State& state)
 
   state.popStateSet();
   state.apply();
+  state.setActiveTextureUnit(0);
+  state.setClientActiveTextureUnit(0);
+
 
   // Draw yellow "hotspots" if directed to.  This is a panel authoring
   // feature; not intended to be high performance or to look good.
   if ( fgGetBool("/sim/panel-hotspots") ) {
-    static osg::ref_ptr<osg::StateSet> hotspotStateSet = new osg::StateSet;
-    hotspotStateSet->setTextureMode(0, GL_TEXTURE_2D, osg::StateAttribute::OFF);
+    static osg::ref_ptr<osg::StateSet> hotspotStateSet;
+    if (!hotspotStateSet.valid()) {
+      hotspotStateSet = new osg::StateSet;
+      hotspotStateSet->setTextureMode(0, GL_TEXTURE_2D, osg::StateAttribute::OFF);
+      hotspotStateSet->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
+    }
+
     state.pushStateSet(hotspotStateSet.get());
     state.apply();
-  
+    state.setActiveTextureUnit(0);
+    state.setClientActiveTextureUnit(0);
+
+
+    glPushAttrib(GL_ENABLE_BIT);
+    glDisable(GL_COLOR_MATERIAL);
     glColor3f(1, 1, 0);
     
     for ( unsigned int i = 0; i < _instruments.size(); i++ )
       _instruments[i]->drawHotspots(state);
+
+    glPopAttrib();
+
     state.popStateSet();
     state.apply();
+    state.setActiveTextureUnit(0);
+    state.setClientActiveTextureUnit(0);
+
   }
 }
 
@@ -651,7 +690,7 @@ FGPanelAction::~FGPanelAction ()
 }
 
 void
-FGPanelAction::addBinding (FGBinding * binding, int updown)
+FGPanelAction::addBinding (SGBinding * binding, int updown)
 {
   _bindings[updown].push_back(binding);
 }
@@ -875,7 +914,7 @@ FGSpecialInstrument::~FGSpecialInstrument ()
 void
 FGSpecialInstrument::draw (osg::State& state)
 {
-  complex->draw();
+  complex->draw(state);
 }
 
 
@@ -1009,6 +1048,9 @@ FGTexturedLayer::draw (osg::State& state)
     transform();
     state.pushStateSet(_texture.getTexture());
     state.apply();
+    state.setActiveTextureUnit(0);
+    state.setClientActiveTextureUnit(0);
+
     glBegin(GL_POLYGON);
 
     if (_emissive) {
@@ -1026,6 +1068,9 @@ FGTexturedLayer::draw (osg::State& state)
     glEnd();
     state.popStateSet();
     state.apply();
+    state.setActiveTextureUnit(0);
+    state.setClientActiveTextureUnit(0);
+
   }
 }
 
@@ -1060,14 +1105,19 @@ FGTextLayer::draw (osg::State& state)
     transform();
 
     FGFontCache *fc = globals->get_fontcache();
-    text_renderer.setFont(fc->getTexFont(_font_name.c_str()));
+    fntFont* font = fc->getTexFont(_font_name.c_str());
+    if (!font) {
+        return; // don't crash on missing fonts
+    }
+    
+    text_renderer.setFont(font);
 
     text_renderer.setPointSize(_pointSize);
     text_renderer.begin();
     text_renderer.start3f(0, 0, 0);
 
     _now.stamp();
-    long diff = _now - _then;
+    double diff = (_now - _then).toUSecs();
 
     if (diff > 100000 || diff < 0 ) {
       // ( diff < 0 ) is a sanity check and indicates our time stamp
@@ -1121,6 +1171,11 @@ void
 FGTextLayer::setFontName(const string &name)
 {
   _font_name = name + ".txf";
+  FGFontCache *fc = globals->get_fontcache();
+  fntFont* font = fc->getTexFont(_font_name.c_str());
+  if (!font) {
+      SG_LOG(SG_GENERAL, SG_WARN, "unable to find font:" << name);
+  }
 }