]> git.mxchange.org Git - flightgear.git/commitdiff
Modified Files:
authorfrohlich <frohlich>
Thu, 3 May 2007 18:47:39 +0000 (18:47 +0000)
committerfrohlich <frohlich>
Thu, 3 May 2007 18:47:39 +0000 (18:47 +0000)
src/Main/renderer.cxx src/Scenery/Makefile.am
Added Files:
src/Scenery/redout.cxx src/Scenery/redout.hxx:
Add simple redout effect.

src/Main/renderer.cxx
src/Scenery/Makefile.am
src/Scenery/redout.cxx [new file with mode: 0644]
src/Scenery/redout.hxx [new file with mode: 0644]

index ee0ee17438abf5c914567d78d2077cabf267b150..3ce641c0c8f849ff9a13722050b0f8a5cd33f040 100644 (file)
@@ -90,6 +90,7 @@
 #include <Model/modelmgr.hxx>
 #include <Model/acmodel.hxx>
 #include <Scenery/scenery.hxx>
+#include <Scenery/redout.hxx>
 #include <Scenery/tilemgr.hxx>
 #include <ATC/ATCdisplay.hxx>
 #include <GUI/new_gui.hxx>
@@ -506,7 +507,7 @@ FGRenderer::init( void ) {
 
     // plug in the GUI
     osg::Camera* guiCamera = new osg::Camera;
-    guiCamera->setRenderOrder(osg::Camera::POST_RENDER);
+    guiCamera->setRenderOrder(osg::Camera::POST_RENDER, 100);
     guiCamera->setClearMask(0);
     inheritanceMask = osg::CullSettings::ALL_VARIABLES;
     inheritanceMask &= ~osg::CullSettings::COMPUTE_NEAR_FAR_MODE;
@@ -548,6 +549,7 @@ FGRenderer::init( void ) {
     sw->addChild(mCameraView.get());
 
     mRealRoot->addChild(sw);
+    mRealRoot->addChild(FGCreateRedoutNode());
     mRealRoot->addChild(guiCamera);
 }
 
index 31e06048dadb3ce2f47ee403a582f39b39c1e12a..a9b03eca8c23feb7fb1f11e66a9ee848cc9c2f9f 100644 (file)
@@ -3,6 +3,7 @@ noinst_LIBRARIES = libScenery.a
 libScenery_a_SOURCES = \
        FGTileLoader.cxx FGTileLoader.hxx \
        newcache.cxx newcache.hxx \
+       redout.cxx redout.hxx \
        scenery.cxx scenery.hxx \
        tileentry.cxx tileentry.hxx \
        tilemgr.cxx tilemgr.hxx
diff --git a/src/Scenery/redout.cxx b/src/Scenery/redout.cxx
new file mode 100644 (file)
index 0000000..b6ff2dc
--- /dev/null
@@ -0,0 +1,116 @@
+// redout.hxx
+//
+// Written by Mathias Froehlich,
+//
+// Copyright (C) 2007  Mathias Froehlich
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 2 of the
+// License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+//
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include "redout.hxx"
+
+#include <assert.h>
+
+#include <osg/BlendFunc>
+#include <osg/Depth>
+#include <osg/Geometry>
+#include <osg/Geode>
+#include <osg/Switch>
+#include <osg/StateSet>
+
+#include <simgear/props/props.hxx>
+#include <Main/fg_props.hxx>
+
+class FGRedoutCallback : public osg::NodeCallback {
+public:
+  FGRedoutCallback(osg::Vec4Array* colorArray) :
+    _colorArray(colorArray),
+    _redoutNode(fgGetNode("/sim/rendering/redout", true))
+  {
+    fgGetNode("/sim/rendering/redout/alpha", true);
+  }
+  virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
+  {
+    assert(dynamic_cast<osg::Switch*>(node));
+    osg::Switch* sw = static_cast<osg::Switch*>(node);
+
+    // Check if we need to do something further ...
+    float alpha = _redoutNode->getFloatValue("alpha", 0);
+    bool enabled = (0 < alpha);
+    sw->setValue(0, enabled);
+    if (!enabled)
+      return;
+
+    (*_colorArray)[0][0] = _redoutNode->getFloatValue("red", 1);
+    (*_colorArray)[0][1] = _redoutNode->getFloatValue("green", 0);
+    (*_colorArray)[0][2] = _redoutNode->getFloatValue("blue", 0);
+    (*_colorArray)[0][3] = alpha;
+    _colorArray->dirty();
+  }
+private:
+  osg::ref_ptr<osg::Vec4Array> _colorArray;
+  SGSharedPtr<SGPropertyNode> _redoutNode;
+};
+
+osg::Node* FGCreateRedoutNode()
+{
+  osg::Geometry* geometry = new osg::Geometry;
+  geometry->setUseDisplayList(false);
+
+  osg::StateSet* stateSet = geometry->getOrCreateStateSet();
+  stateSet->setMode(GL_ALPHA_TEST, osg::StateAttribute::OFF);
+  stateSet->setMode(GL_BLEND, osg::StateAttribute::ON);
+  stateSet->setAttribute(new osg::BlendFunc);
+  stateSet->setMode(GL_CULL_FACE, osg::StateAttribute::OFF);
+  stateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF);
+  stateSet->setAttribute(new osg::Depth(osg::Depth::ALWAYS, 0, 1, false));
+  stateSet->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
+
+  osg::Vec3Array* vertexArray = new osg::Vec3Array;
+  vertexArray->push_back(osg::Vec3(-1, -1, 0));
+  vertexArray->push_back(osg::Vec3( 1, -1, 0));
+  vertexArray->push_back(osg::Vec3( 1,  1, 0));
+  vertexArray->push_back(osg::Vec3(-1,  1, 0));
+  geometry->setVertexArray(vertexArray);
+  osg::Vec4Array* colorArray = new osg::Vec4Array;
+  colorArray->push_back(osg::Vec4(1, 0, 0, 1));
+  geometry->setColorArray(colorArray);
+  geometry->setColorBinding(osg::Geometry::BIND_OVERALL);
+  geometry->addPrimitiveSet(new osg::DrawArrays(GL_POLYGON, 0, 4));
+
+  osg::Geode* geode = new osg::Geode;
+  geode->addDrawable(geometry);
+
+  osg::Camera* camera = new osg::Camera;
+  camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
+  camera->setProjectionMatrix(osg::Matrix::ortho2D(-1, 1, -1, 1));
+  camera->setViewMatrix(osg::Matrix::identity());
+  camera->setRenderOrder(osg::Camera::POST_RENDER, 10);
+  camera->setClearMask(0);
+  camera->setAllowEventFocus(false);
+  camera->setCullingActive(false);
+  camera->addChild(geode);
+
+  osg::Switch* sw = new osg::Switch;
+  sw->setUpdateCallback(new FGRedoutCallback(colorArray));
+  sw->addChild(camera);
+
+  return sw;
+}
+
diff --git a/src/Scenery/redout.hxx b/src/Scenery/redout.hxx
new file mode 100644 (file)
index 0000000..764e1fc
--- /dev/null
@@ -0,0 +1,29 @@
+// redout.hxx
+//
+// Written by Mathias Froehlich,
+//
+// Copyright (C) 2007  Mathias Froehlich
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 2 of the
+// License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+//
+
+#ifndef FG_REDOUT_HXX
+#define FG_REDOUT_HXX
+
+#include <osg/Node>
+
+extern osg::Node* FGCreateRedoutNode();
+
+#endif