From 19e2e7a461fc0fb22ae2e122cd89fa99591d15a7 Mon Sep 17 00:00:00 2001 From: frohlich Date: Thu, 3 May 2007 18:47:39 +0000 Subject: [PATCH] Modified Files: 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 | 4 +- src/Scenery/Makefile.am | 1 + src/Scenery/redout.cxx | 116 ++++++++++++++++++++++++++++++++++++++++ src/Scenery/redout.hxx | 29 ++++++++++ 4 files changed, 149 insertions(+), 1 deletion(-) create mode 100644 src/Scenery/redout.cxx create mode 100644 src/Scenery/redout.hxx diff --git a/src/Main/renderer.cxx b/src/Main/renderer.cxx index ee0ee1743..3ce641c0c 100644 --- a/src/Main/renderer.cxx +++ b/src/Main/renderer.cxx @@ -90,6 +90,7 @@ #include #include #include +#include #include #include #include @@ -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); } diff --git a/src/Scenery/Makefile.am b/src/Scenery/Makefile.am index 31e06048d..a9b03eca8 100644 --- a/src/Scenery/Makefile.am +++ b/src/Scenery/Makefile.am @@ -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 index 000000000..b6ff2dc4d --- /dev/null +++ b/src/Scenery/redout.cxx @@ -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 +#endif + +#include "redout.hxx" + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include
+ +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(node)); + osg::Switch* sw = static_cast(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 _colorArray; + SGSharedPtr _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 index 000000000..764e1fc7c --- /dev/null +++ b/src/Scenery/redout.hxx @@ -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 + +extern osg::Node* FGCreateRedoutNode(); + +#endif