-// done here and not in init() so we don't allocate a rendering context if it is
-// never used
-void FGODGauge::allocRT () {
- GLint colorBits = 0;
- glGetIntegerv( GL_BLUE_BITS, &colorBits );
- textureWH = 256;
- rt = new RenderTexture();
- if( colorBits < 8 )
- rt->Reset("rgba=5,5,5,1 ctt");
- else
- rt->Reset("rgba ctt");
-
- if( rt->Initialize(256, 256, true) ) {
- SG_LOG(SG_ALL, SG_INFO, "FGODGauge:Initialize sucessfull");
- if (rt->BeginCapture())
- {
- SG_LOG(SG_ALL, SG_INFO, "FGODGauge:BeginCapture sucessfull, RTT available");
- rtAvailable = true;
- glViewport(0, 0, textureWH, textureWH);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluOrtho2D( -256.0, 256.0, -256.0, 256.0 );
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glDisable(GL_LIGHTING);
- glEnable(GL_COLOR_MATERIAL);
- glDisable(GL_CULL_FACE);
- glDisable(GL_FOG);
- glDisable(GL_DEPTH_TEST);
- glClearColor(0.0, 0.0, 0.0, 0.0);
- glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
- glBindTexture(GL_TEXTURE_2D, 0);
- glEnable(GL_TEXTURE_2D);
- glEnable(GL_ALPHA_TEST);
- glAlphaFunc(GL_GREATER, 0.0f);
- glDisable(GL_SMOOTH);
- glEnable(GL_BLEND);
- glBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_ALPHA );
- rt->EndCapture();
- } else
- SG_LOG(SG_ALL, SG_WARN, "FGODGauge:BeginCapture failed, RTT not available, using backbuffer");
- } else
- SG_LOG(SG_ALL, SG_WARN, "FGODGauge:Initialize failed, RTT not available, using backbuffer");
-}
-
-FGODGauge::~FGODGauge() {
- delete rt;
-}
-
-void FGODGauge::init () {
-}
-
-void FGODGauge::update (double dt) {
-}
-
-void FGODGauge::beginCapture(int viewSize) {
- if( ! rt )
- allocRT();
- if(rtAvailable) {
- rt->BeginCapture();
- }
- else
- set2D();
- textureWH = viewSize;
- glViewport(0, 0, textureWH, textureWH);
-}
-
-void FGODGauge::beginCapture(void) {
- if( ! rt )
- allocRT();
- if(rtAvailable) {
- rt->BeginCapture();
+void FGODGauge::allocRT ()
+{
+ camera = new osg::Camera;
+ // Only the far camera should trigger this texture to be rendered.
+ camera->setNodeMask(simgear::BACKGROUND_BIT);
+ camera->setProjectionMatrix(osg::Matrix::ortho2D(-textureWH/2.0, textureWH/2.0, -textureWH/2.0, textureWH/2.0));
+ camera->setViewport(0, 0, textureWH, textureWH);
+ camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
+ camera->setRenderOrder(osg::Camera::PRE_RENDER);
+ camera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ camera->setClearColor(osg::Vec4(0.0f, 0.0f, 0.0f , 0.0f));
+ camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT, osg::Camera::FRAME_BUFFER);
+ osg::StateSet* stateSet = camera->getOrCreateStateSet();
+ stateSet->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
+ stateSet->setMode(GL_CULL_FACE, osg::StateAttribute::OFF);
+ stateSet->setMode(GL_FOG, osg::StateAttribute::OFF);
+ stateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF);
+ stateSet->setAttributeAndModes(new osg::PolygonMode(osg::PolygonMode::FRONT_AND_BACK,
+ osg::PolygonMode::FILL),
+ osg::StateAttribute::ON);
+ stateSet->setAttributeAndModes(new osg::AlphaFunc(osg::AlphaFunc::GREATER,
+ 0.0f),
+ osg::StateAttribute::ON);
+ stateSet->setAttribute(new osg::ShadeModel(osg::ShadeModel::FLAT));
+ stateSet->setAttributeAndModes(new osg::BlendFunc(osg::BlendFunc::SRC_ALPHA,
+ osg::BlendFunc::ONE_MINUS_SRC_ALPHA),
+ osg::StateAttribute::ON);
+ if (!texture.valid()) {
+ texture = new osg::Texture2D;
+ texture->setTextureSize(textureWH, textureWH);
+ texture->setInternalFormat(GL_RGBA);
+ texture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR);
+ texture->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR);