]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/main.cxx
make isatty() available for stdout/stderr (hope it works on MS Windows)
[flightgear.git] / src / Main / main.cxx
index ba2483da0b413d7393f28c4d1ad103c12c5c6156..b38b3536a2ba51466a124a0c2e2f23d83e8176b3 100644 (file)
 #  include <signal.h>
 #endif
 
-#ifdef SG_MATH_EXCEPTION_CLASH
-#  include <math.h>
-#endif
-
-#ifdef HAVE_WINDOWS_H
-#  include <windows.h>
-#  include <float.h>
-#endif
+#include <iostream>
 
 #include <plib/netSocket.h>
 
-#include <simgear/props/props.hxx>
-#include <simgear/timing/sg_time.hxx>
-#include <simgear/math/sg_random.h>
-
+#include <osg/Camera>
+#include <osg/GraphicsContext>
 #include <osgDB/Registry>
 
 // Class references
 #include <simgear/scene/material/matlib.hxx>
 #include <simgear/scene/model/animation.hxx>
 #include <simgear/scene/sky/sky.hxx>
+#include <simgear/structure/event_mgr.hxx>
+#include <simgear/props/props.hxx>
+#include <simgear/timing/sg_time.hxx>
+#include <simgear/math/sg_random.h>
+
 #include <Time/light.hxx>
 #include <Include/general.hxx>
 #include <Aircraft/replay.hxx>
 #include <GUI/new_gui.hxx>
 #include <MultiPlayer/multiplaymgr.hxx>
 
+#include "CameraGroup.hxx"
 #include "fg_commands.hxx"
 #include "fg_io.hxx"
 #include "renderer.hxx"
 #include "splash.hxx"
 #include "main.hxx"
 #include "util.hxx"
+#include "fg_init.hxx"
+#include "WindowSystemAdapter.hxx"
 
 
 static double real_delta_time_sec = 0.0;
 double delta_time_sec = 0.0;
 extern float init_volume;
 
+using namespace flightgear;
+
+using std::cerr;
+
 // This is a record containing a bit of global housekeeping information
 FGGeneral general;
 
@@ -658,21 +661,18 @@ static void fgMainLoop( void ) {
     SG_LOG( SG_ALL, SG_DEBUG, "" );
 }
 
-
-// This is the top level master main function that is registered as
-// our idle funciton
-
-// The first few passes take care of initialization things (a couple
-// per pass) and once everything has been initialized fgMainLoop from
-// then on.
-
-static void fgIdleFunction ( void ) {
-    if ( idle_state == 0 ) {
-        idle_state++;
-
-        // This seems to be the absolute earliest in the init sequence
-        // that these calls will return valid info.  Too bad it's after
-        // we've already created and sized our window. :-(
+// Operation for querying OpenGL parameters. This must be done in a
+// valid OpenGL context, potentially in another thread.
+namespace
+{
+struct GeneralInitOperation : public GraphicsContextOperation
+{
+    GeneralInitOperation()
+        : GraphicsContextOperation(std::string("General init"))
+    {
+    }
+    void run(osg::GraphicsContext* gc)
+    {
         general.set_glVendor( (char *)glGetString ( GL_VENDOR ) );
         general.set_glRenderer( (char *)glGetString ( GL_RENDERER ) );
         general.set_glVersion( (char *)glGetString ( GL_VERSION ) );
@@ -686,12 +686,42 @@ static void fgIdleFunction ( void ) {
         glGetIntegerv( GL_DEPTH_BITS, &tmp );
         general.set_glDepthBits( tmp );
         SG_LOG ( SG_GENERAL, SG_INFO, "Depth buffer bits = " << tmp );
+    }
+};
+}
 
-        // Initialize the user interface so that we can use fonts
-        guiStartInit();
+// This is the top level master main function that is registered as
+// our idle funciton
 
+// The first few passes take care of initialization things (a couple
+// per pass) and once everything has been initialized fgMainLoop from
+// then on.
 
+static void fgIdleFunction ( void ) {
+    static osg::ref_ptr<GeneralInitOperation> genOp;
+    if ( idle_state == 0 ) {
+        idle_state++;
+        // Pick some window on which to do queries.
+        // XXX Perhaps all this graphics initialization code should be
+        // moved to renderer.cxx?
+        genOp = new GeneralInitOperation;
+        osg::Camera* guiCamera = getGUICamera(CameraGroup::getDefault());
+        WindowSystemAdapter* wsa = WindowSystemAdapter::getWSA();
+        osg::GraphicsContext* gc = 0;
+        if (guiCamera)
+            gc = guiCamera->getGraphicsContext();
+        if (gc) {
+            gc->add(genOp.get());
+        } else {
+            wsa->windows[0]->gc->add(genOp.get());
+        }
+        guiStartInit(gc);
     } else if ( idle_state == 1 ) {
+        if (genOp.valid()) {
+            if (!genOp->isFinished())
+                return;
+            genOp = 0;
+        }
         if (!guiFinishInit())
             return;
         idle_state++;