]> git.mxchange.org Git - flightgear.git/blobdiff - src/Cockpit/hud.cxx
Port over remaining Point3D usage to the more type and unit safe SG* classes.
[flightgear.git] / src / Cockpit / hud.cxx
index ad2e65811d0eac39c0ea85486981961d1fbe8f4b..e6903caabbdb287910d472112eaefee5586bfb58 100644 (file)
 #include <simgear/compiler.h>
 #include <simgear/structure/exception.hxx>
 
-#include STL_STRING
-#include STL_FSTREAM
+#include <string>
+#include <fstream>
 
 #ifdef HAVE_CONFIG_H
 #  include <config.h>
 #endif
 
-#ifdef HAVE_WINDOWS_H
-#  include <windows.h>
-#endif
-
-#ifdef __BORLANDC__
-#  define exception c_exception
-#endif
-
 #include <math.h>
-
 #include <stdlib.h>
 #include <stdio.h>              // char related functions
 #include <string.h>             // strcmp()
 
-#include SG_GLU_H
-
 #include <simgear/constants.h>
 #include <simgear/debug/logstream.hxx>
 #include <simgear/misc/sg_path.hxx>
+#include <simgear/props/props_io.hxx>
+
+#include <osg/GLU>
 
 #include <Aircraft/aircraft.hxx>
 //#include <Autopilot/xmlauto.hxx>
 #include <GUI/new_gui.hxx>           // FGFontCache
 #include <Main/globals.hxx>
-#include <Main/fg_props.hxx>
 #include <Scenery/scenery.hxx>
+#include <Airports/runways.hxx>
 
 #include "hud.hxx"
 
@@ -64,7 +56,7 @@ static HUD_Properties *HUDprop = 0;
 
 static char units[5];
 
-deque<instr_item *> HUD_deque;
+deque<SGSharedPtr<instr_item> > HUD_deque;
 
 fgTextList HUD_TextList;
 fgLineList HUD_LineList;
@@ -80,8 +72,8 @@ float HUD_matrix[16];
 int readHud( istream &input );
 int readInstrument ( const SGPropertyNode * node);
 
-static void drawHUD();
-static void fgUpdateHUDVirtual();
+static void drawHUD(osg::State*);
+static void fgUpdateHUDVirtual(osg::State*);
 
 
 class locRECT {
@@ -192,6 +184,8 @@ int readHud( istream &input )
     SG_LOG(SG_INPUT, SG_INFO, "Read properties for  " <<
            root.getStringValue("name"));
 
+    if (!root.getNode("depreciated"))
+        SG_LOG(SG_INPUT, SG_ALERT, "WARNING: use of depreciated old HUD");
 
     HUD_deque.erase( HUD_deque.begin(), HUD_deque.end());
 
@@ -256,8 +250,6 @@ int fgHUDInit( fgAIRCRAFT * /* current_aircraft */ )
         input.close();
     }
 
-    fgHUDReshape();
-
     if ( HUDtext ) {
         // this chunk of code is not necessarily thread safe if the
         // compiler optimizer reorders these statements.  Note that
@@ -315,39 +307,17 @@ int fgHUDInit2( fgAIRCRAFT * /* current_aircraft */ )
 //$$$ End - added, Neetha, 28 Nov 2k
 
 
-void fgHUDReshape(void) {
-#if 0
-    if ( HUDtext ) {
-        // this chunk of code is not necessarily thread safe if the
-        // compiler optimizer reorders these statements.  Note that
-        // "delete ptr" does not set "ptr = NULL".  We have to do that
-        // ourselves.
-        fntRenderer *tmp = HUDtext;
-        HUDtext = NULL;
-        delete tmp;
-    }
-
-    HUD_TextSize = fgGetInt("/sim/startup/xsize") / 60;
-    HUD_TextSize = 10;
-    HUDtext = new fntRenderer();
-    HUDtext -> setFont      ( guiFntHandle ) ;
-    HUDtext -> setPointSize ( HUD_TextSize ) ;
-    HUD_TextList.setFont( HUDtext );
-#endif
-}
-
-
 // fgUpdateHUD
 //
 // Performs a once around the list of calls to instruments installed in
 // the HUD object with requests for redraw. Kinda. It will when this is
 // all C++.
 //
-void fgUpdateHUD( void ) {
+void fgUpdateHUD( osg::State* state ) {
 
     static const SGPropertyNode *enable3d_node = fgGetNode("/sim/hud/enable3d");
     if ( HUD_style == 1 && enable3d_node->getBoolValue() ) {
-        fgUpdateHUDVirtual();
+        fgUpdateHUDVirtual(state);
         return;
     }
 
@@ -357,15 +327,15 @@ void fgUpdateHUD( void ) {
     if ( current_aspect > normal_aspect ) {
         float aspect_adjust = current_aspect / normal_aspect;
         float adjust = 320.0f*aspect_adjust - 320.0f;
-        fgUpdateHUD( -adjust, 0.0f, 640.0f+adjust, 480.0f );
+        fgUpdateHUD( state, -adjust, 0.0f, 640.0f+adjust, 480.0f );
     } else {
         float aspect_adjust = normal_aspect / current_aspect;
         float adjust = 240.0f*aspect_adjust - 240.0f;
-        fgUpdateHUD( 0.0f, -adjust, 640.0f, 480.0f+adjust );
+        fgUpdateHUD( state, 0.0f, -adjust, 640.0f, 480.0f+adjust );
     }
 }
 
-void fgUpdateHUDVirtual()
+void fgUpdateHUDVirtual(osg::State* state)
 {
     FGViewer* view = globals->get_current_view();
 
@@ -407,7 +377,7 @@ void fgUpdateHUDVirtual()
     glTranslatef(-320, -240, -1);
 
     // Do the deed
-    drawHUD();
+    drawHUD(state);
 
     // Clean up our mess
     glMatrixMode(GL_PROJECTION);
@@ -417,7 +387,7 @@ void fgUpdateHUDVirtual()
 }
 
 
-void fgUpdateHUD( GLfloat x_start, GLfloat y_start,
+void fgUpdateHUD( osg::State* state, GLfloat x_start, GLfloat y_start,
                   GLfloat x_end, GLfloat y_end )
 {
     glMatrixMode(GL_PROJECTION);
@@ -429,7 +399,7 @@ void fgUpdateHUD( GLfloat x_start, GLfloat y_start,
     glPushMatrix();
     glLoadIdentity();
 
-    drawHUD();
+    drawHUD(state);
 
     glMatrixMode(GL_PROJECTION);
     glPopMatrix();
@@ -438,7 +408,7 @@ void fgUpdateHUD( GLfloat x_start, GLfloat y_start,
 }
 
 
-void drawHUD()
+void drawHUD(osg::State* state)
 {
     if ( !HUD_deque.size() ) // Trust everyone, but ALWAYS cut the cards!
         return;
@@ -548,6 +518,9 @@ void drawHUD()
         //glLineWidth(1.0);
     }
 
+    if (HUDprop->isTransparent())
+        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
     glEnable(GL_DEPTH_TEST);
     glEnable(GL_LIGHTING);
 }
@@ -562,6 +535,7 @@ void fgTextList::draw()
     vector<fgText>::iterator lastString = List.end();
 
     glPushAttrib(GL_COLOR_BUFFER_BIT);
+    glEnable(GL_TEXTURE_2D);
     glEnable(GL_BLEND);
     if (HUDprop->isTransparent())
         glBlendFunc(GL_SRC_ALPHA, GL_ONE);
@@ -575,7 +549,7 @@ void fgTextList::draw()
 
     Font->begin();
     for (; curString != lastString; curString++)
-        curString->Draw(Font,curString->digit);
+        curString->Draw(Font);
     Font->end();
 
     glDisable(GL_TEXTURE_2D);