3 // Written by Mathias Froehlich,
5 // Copyright (C) 2007 Mathias Froehlich
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
30 #include <osg/BlendFunc>
32 #include <osg/Geometry>
35 #include <osg/StateSet>
37 #include <simgear/props/props.hxx>
38 #include <Main/fg_props.hxx>
40 class FGRedoutCallback : public osg::NodeCallback {
42 FGRedoutCallback(osg::Vec4Array* colorArray) :
43 _colorArray(colorArray),
44 _redoutNode(fgGetNode("/sim/rendering/redout", true))
46 fgGetNode("/sim/rendering/redout/alpha", true);
48 virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
50 assert(dynamic_cast<osg::Switch*>(node));
51 osg::Switch* sw = static_cast<osg::Switch*>(node);
53 // Check if we need to do something further ...
54 float alpha = _redoutNode->getFloatValue("alpha", 0);
55 bool enabled = (0 < alpha);
56 sw->setValue(0, enabled);
60 (*_colorArray)[0][0] = _redoutNode->getFloatValue("red", 1);
61 (*_colorArray)[0][1] = _redoutNode->getFloatValue("green", 0);
62 (*_colorArray)[0][2] = _redoutNode->getFloatValue("blue", 0);
63 (*_colorArray)[0][3] = alpha;
67 osg::ref_ptr<osg::Vec4Array> _colorArray;
68 SGSharedPtr<SGPropertyNode> _redoutNode;
71 osg::Node* FGCreateRedoutNode()
73 osg::Geometry* geometry = new osg::Geometry;
74 geometry->setUseDisplayList(false);
76 osg::StateSet* stateSet = geometry->getOrCreateStateSet();
77 stateSet->setMode(GL_ALPHA_TEST, osg::StateAttribute::OFF);
78 stateSet->setMode(GL_BLEND, osg::StateAttribute::ON);
79 stateSet->setAttribute(new osg::BlendFunc);
80 stateSet->setMode(GL_CULL_FACE, osg::StateAttribute::OFF);
81 stateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF);
82 stateSet->setAttribute(new osg::Depth(osg::Depth::ALWAYS, 0, 1, false));
83 stateSet->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
85 osg::Vec3Array* vertexArray = new osg::Vec3Array;
86 vertexArray->push_back(osg::Vec3(-1, -1, 0));
87 vertexArray->push_back(osg::Vec3( 1, -1, 0));
88 vertexArray->push_back(osg::Vec3( 1, 1, 0));
89 vertexArray->push_back(osg::Vec3(-1, 1, 0));
90 geometry->setVertexArray(vertexArray);
91 osg::Vec4Array* colorArray = new osg::Vec4Array;
92 colorArray->push_back(osg::Vec4(1, 0, 0, 1));
93 geometry->setColorArray(colorArray);
94 geometry->setColorBinding(osg::Geometry::BIND_OVERALL);
95 geometry->addPrimitiveSet(new osg::DrawArrays(GL_POLYGON, 0, 4));
97 osg::Geode* geode = new osg::Geode;
98 geode->addDrawable(geometry);
100 osg::Camera* camera = new osg::Camera;
101 camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
102 camera->setProjectionMatrix(osg::Matrix::ortho2D(-1, 1, -1, 1));
103 camera->setViewMatrix(osg::Matrix::identity());
104 camera->setRenderOrder(osg::Camera::POST_RENDER, 10);
105 camera->setClearMask(0);
106 camera->setAllowEventFocus(false);
107 camera->setCullingActive(false);
108 camera->addChild(geode);
110 osg::Switch* sw = new osg::Switch;
111 sw->setUpdateCallback(new FGRedoutCallback(colorArray));
112 sw->addChild(camera);