+FGPanel::draw(osg::State& state)
+{
+ // In 3D mode, it's possible that we are being drawn exactly on top
+ // of an existing polygon. Use an offset to prevent z-fighting. In
+ // 2D mode, this is a no-op.
+ static osg::ref_ptr<osg::StateSet> panelStateSet;
+ if (!panelStateSet.valid()) {
+ panelStateSet = new osg::StateSet;
+ panelStateSet->setAttributeAndModes(new osg::PolygonOffset(-1, -POFF_UNITS));
+ panelStateSet->setTextureAttribute(0, new osg::TexEnv);
+
+ // Draw the background
+ panelStateSet->setTextureMode(0, GL_TEXTURE_2D, osg::StateAttribute::ON);
+ panelStateSet->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
+ panelStateSet->setMode(GL_BLEND, osg::StateAttribute::ON);
+ panelStateSet->setMode(GL_ALPHA_TEST, osg::StateAttribute::ON);
+ osg::Material* material = new osg::Material;
+ material->setColorMode(osg::Material::AMBIENT_AND_DIFFUSE);
+ material->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4(1, 1, 1, 1));
+ material->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4(1, 1, 1, 1));
+ 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_CULL_FACE, osg::StateAttribute::ON);
+ panelStateSet->setAttributeAndModes(new osg::CullFace(osg::CullFace::BACK));
+ 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().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;
+ if ( panel_color[2] < 0.2 ) panel_color[2] = 0.2;
+ }
+ glColor4fv( panel_color );
+ if (_bg != 0) {
+ state.pushStateSet(_bg.get());
+ state.apply();
+ state.setActiveTextureUnit(0);
+ state.setClientActiveTextureUnit(0);