]> git.mxchange.org Git - flightgear.git/blobdiff - src/Instrumentation/render_area_2d.cxx
MapWidget for the GUI, initial commit.
[flightgear.git] / src / Instrumentation / render_area_2d.cxx
index 6338e3082cdcc843a896cce4dc16536715a4d337..c0da87fd76297f777d05ac13ef514e4b63e9d107 100644 (file)
 //
 // $Id$
 
-#include "render_area_2d.hxx"
-//#include <iostream>
-
-#include <plib/ssg.h>
-
-//using namespace std;
 
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
 
-
-static const float dummy_normals[][3] = {{0.0f, 0.0f, 0.0f},
-                                         {0.0f, 0.0f, 0.0f},
-                                         {0.0f, 0.0f, 0.0f},
-                                         {0.0f, 0.0f, 0.0f}};
+#include "render_area_2d.hxx"
 
 RA2DPrimitive::RA2DPrimitive() {
        invert = false;
@@ -64,23 +57,31 @@ RenderArea2D::RenderArea2D(int logx, int logy, int sizex, int sizey, int posx, i
        _ra2d_debug = false;
 }
 
-void RenderArea2D::draw() {
-    glDisable(GL_TEXTURE_2D);
-       /*
-    glColor3f(1, 1, 0);
+void RenderArea2D::draw(osg::State& state) {
        
-       float x1 = _posx;
-       float x2 = _posx + _sizex;
-       float y1 = _posy;
-       float y2 = _posy + _sizey;
+       static osg::ref_ptr<osg::StateSet> renderArea2DStateSet;
+       if(!renderArea2DStateSet.valid()) {
+               renderArea2DStateSet = new osg::StateSet;
+               renderArea2DStateSet->setTextureMode(0, GL_TEXTURE_2D, osg::StateAttribute::OFF);
+               renderArea2DStateSet->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
+       }
+       
+       state.pushStateSet(renderArea2DStateSet.get());
+       state.apply();
+       state.setActiveTextureUnit(0);
+       state.setClientActiveTextureUnit(0);
+       
+       // DCL - the 2 lines below are copied verbatim from the hotspot drawing code.
+       // I am not sure if they are needed here or not.
+       glPushAttrib(GL_ENABLE_BIT);
+       glDisable(GL_COLOR_MATERIAL);
        
-       glBegin(GL_LINE_LOOP);
-    glVertex2f(x1, y1);
-    glVertex2f(x1, y2);
-    glVertex2f(x2, y2);
-    glVertex2f(x2, y1);
-    glEnd();
-       */
+       // FIXME - disabling all clip planes causes bleed-through through the splash screen.
+       glDisable(GL_CLIP_PLANE0);
+       glDisable(GL_CLIP_PLANE1);
+       glDisable(GL_CLIP_PLANE2);
+       glDisable(GL_CLIP_PLANE3);
+
        oldDrawBackground();
        
        for(unsigned int i = 0; i < drawing_list.size(); ++i) {
@@ -102,7 +103,12 @@ void RenderArea2D::draw() {
                }
        }
        
-       glEnable(GL_TEXTURE_2D);
+       glPopAttrib();
+       
+       state.popStateSet();
+       state.apply();
+       state.setActiveTextureUnit(0);
+       state.setClientActiveTextureUnit(0);
 }
 
 // Set clipping region in logical units
@@ -173,13 +179,13 @@ void RenderArea2D::oldDrawPixel(int x, int y, bool invert) {
        //cout << "DP: " << fx1 << ", " << fy1 << " ... " << fx2 << ", " << fy2 << '\n';
        
        doSetColor(invert ? _backgroundColor : _pixelColor);
-       sgVec2 corners[4];
-       sgSetVec2(corners[0], fx1, fy1);
-       sgSetVec2(corners[1], fx2, fy1);
-       sgSetVec2(corners[2], fx2, fy2);
-       sgSetVec2(corners[3], fx1, fy2);
-       //cout << "Drawing pixel, x,y is " << x << ", " << y << ", fx is [x1,x2,y1,y2] " << fx1 << ", " << fx2 << ", " << fy1 << ", " << fy2 << '\n';
-       doDrawQuad(&corners[0], dummy_normals);
+       SGVec2f corners[4] = {
+    SGVec2f(fx1, fy1),
+    SGVec2f(fx2, fy1),
+    SGVec2f(fx2, fy2),
+    SGVec2f(fx1, fy2)
+  };
+       doDrawQuad(corners);
 }
 
 void RenderArea2D::DrawLine(int x1, int y1, int x2, int y2) {
@@ -303,12 +309,13 @@ void RenderArea2D::oldDrawQuad(int x1, int y1, int x2, int y2, bool invert) {
        //cout << "DP: " << fx1 << ", " << fy1 << " ... " << fx2 << ", " << fy2 << '\n';
        
        doSetColor(invert ? _backgroundColor : _pixelColor);
-       sgVec2 corners[4];
-       sgSetVec2(corners[0], fx1, fy1);
-       sgSetVec2(corners[1], fx2, fy1);
-       sgSetVec2(corners[2], fx2, fy2);
-       sgSetVec2(corners[3], fx1, fy2);
-       doDrawQuad(&corners[0], dummy_normals);
+       SGVec2f corners[4] = {
+    SGVec2f(fx1, fy1),
+    SGVec2f(fx2, fy1),
+    SGVec2f(fx2, fy2),
+    SGVec2f(fx1, fy2)
+  };
+       doDrawQuad(corners);
 }
 
 void RenderArea2D::DrawBackground() {
@@ -317,12 +324,14 @@ void RenderArea2D::DrawBackground() {
 
 void RenderArea2D::oldDrawBackground() {
        doSetColor(_backgroundColor);
-       sgVec2 corners[4];
-       sgSetVec2(corners[0], (float)_posx, (float)_posy);
-       sgSetVec2(corners[1], (float)(_posx + _sizex), (float)_posy);
-       sgSetVec2(corners[2], (float)(_posx + _sizex), (float)(_posy + _sizey));
-       sgSetVec2(corners[3], (float)_posx, (float)(_posy + _sizey));
-       doDrawQuad(&corners[0], dummy_normals);
+       SGVec2f corners[4] = {
+    SGVec2f(_posx, _posy),
+    SGVec2f(_posx + _sizex, _posy),
+    SGVec2f(_posx + _sizex, _posy + _sizey),
+    SGVec2f(_posx, _posy + _sizey)
+  };
+  
+       doDrawQuad(corners);
 }
 
 void RenderArea2D::Flush() {
@@ -340,21 +349,23 @@ void RenderArea2D::doSetColor( const float *rgba ) {
   glColor4fv( rgba );
 }
 
-void RenderArea2D::doDrawQuad( const sgVec2 *p, const sgVec3 *normals ) {
-       //cout << "doDrawQuad: " << *p[0] << ", " << *(p[0]+1) << ", " << *p[1] << ", " << *(p[1]+1) << ", " << *p[2] << ", " << *p([2]+1) << ", " << *p[3] << ", " << *p([3]+1) <<'\n';
+void RenderArea2D::doDrawQuad( const SGVec2f *p) {
   glBegin(GL_QUADS);
-  glNormal3fv( normals[0] ); glVertex2fv( p[0] );
-  glNormal3fv( normals[1] ); glVertex2fv( p[1] );
-  glNormal3fv( normals[2] ); glVertex2fv( p[2] );
-  glNormal3fv( normals[3] ); glVertex2fv( p[3] );
+    glNormal3f(0.0f, 0.0f, 0.0f);
+    glVertex2fv( p[0].data() );
+    glVertex2fv( p[1].data() );
+    glVertex2fv( p[2].data() );
+    glVertex2fv( p[3].data() );
   glEnd();
 }
 
-void RenderArea2D::doDrawQuad( const sgVec2 *p, const sgVec3 *normals, const sgVec4 *color ) {
+void RenderArea2D::doDrawQuad( const SGVec2f *p, const SGVec4f *color ) {
+  
   glBegin(GL_QUADS);
-    glColor4fv( color[0] );glNormal3fv( normals[0] ); glVertex2fv( p[0] );
-    glColor4fv( color[1] );glNormal3fv( normals[1] ); glVertex2fv( p[1] );
-    glColor4fv( color[2] );glNormal3fv( normals[2] ); glVertex2fv( p[2] );
-    glColor4fv( color[3] );glNormal3fv( normals[3] ); glVertex2fv( p[3] );
+    glNormal3f(0.0f, 0.0f, 0.0f);
+    glColor4fv( color[0].data() ); glVertex2fv( p[0].data() );
+    glColor4fv( color[1].data() ); glVertex2fv( p[1].data() );
+    glColor4fv( color[2].data() ); glVertex2fv( p[2].data() );
+    glColor4fv( color[3].data() ); glVertex2fv( p[3].data() );
   glEnd();
 }