-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(-256.0, 256.0, -256.0,
- 256.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);
- }
- camera->attach(osg::Camera::COLOR_BUFFER, texture.get());
- globals->get_renderer()->addCamera(camera.get(), false);
- rtAvailable = true;
-
- // GLint colorBits = 0;
-// glGetIntegerv( GL_BLUE_BITS, &colorBits );
-// 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()
+{
+ if( camera.valid() )
+ globals->get_renderer()->removeCamera(camera.get());
+}
+
+//------------------------------------------------------------------------------
+void FGODGauge::setSize(int size_x, int size_y)
+{
+ _size_x = size_x;
+ _size_y = size_y < 0 ? size_x : size_y;
+
+ if( texture.valid() )
+ texture->setTextureSize(_size_x, _size_x);
+}
+
+//----------------------------------------------------------------------------
+void FGODGauge::setViewSize(int width, int height)
+{
+ _view_width = width;
+ _view_height = height < 0 ? width : height;
+
+ if( camera )
+ updateCoordinateFrame();
+}
+
+//------------------------------------------------------------------------------
+void FGODGauge::useImageCoords(bool use)
+{
+ if( use == _use_image_coords )
+ return;
+
+ _use_image_coords = use;
+
+ if( texture )
+ updateCoordinateFrame();
+}
+
+//------------------------------------------------------------------------------
+void FGODGauge::useStencil(bool use)
+{
+ if( use == _use_stencil )
+ return;
+
+ _use_stencil = use;
+
+ if( texture )
+ updateStencil();