]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/fg_os.cxx
header cleanups
[flightgear.git] / src / Main / fg_os.cxx
index bdd3ba4db7efdeba1b906355437c7e3c23c8673a..0ecde2c921f7dc8a67b36ddaf4b43fa23499b085 100644 (file)
 
 #include <simgear/compiler.h>
 
-#include SG_GLUT_H
-
+#if defined( __APPLE__)
+# include <GLUT/glut.h>
+#else
+# include <GL/glut.h>
+#endif
 #include <plib/pu.h>
 
 #include <Scenery/scenery.hxx>
 #include "globals.hxx"
 #include "renderer.hxx"
 #include "fg_props.hxx"
+#include "WindowSystemAdapter.hxx"
 
-// We need to flush all pending mouse move events past a mouse warp to avoid
-// a race condition ending in warping twice and having huge increments for the
-// second warp.
-// I am not aware of such a flush function in glut. So we emulate that by
-// ignoring mouse move events between a warp mouse and the next frame.
-static bool mouseWarped = false;
+using namespace flightgear;
 
 //
 // Native glut callbacks.
@@ -85,7 +84,7 @@ static void callKeyHandler(int k, int mods, int x, int y)
 
 static void GLUTmotion (int x, int y)
 {
-    if (mouseWarped || !gw.valid())
+    if (!gw.valid())
         return;
     gw->getEventQueue()->mouseMotion(x, y);
 }
@@ -143,7 +142,6 @@ static void GLUTdraw()
     viewer->frame();
     glutSwapBuffers();
     glutPostRedisplay();
-    mouseWarped = false;
 }
 
 static void GLUTreshape(int w, int h)
@@ -161,6 +159,7 @@ static void GLUTreshape(int w, int h)
 void fgOSInit(int* argc, char** argv)
 {
     glutInit(argc, argv);
+    WindowSystemAdapter::setWSA(new WindowSystemAdapter);
 }
 
 void fgOSFullScreen()
@@ -199,7 +198,7 @@ void fgSetMouseCursor(int cursor)
 
 void fgWarpMouse(int x, int y)
 {
-    mouseWarped = true;
+    globals->get_renderer()->getManipulator()->setMouseWarped();
     glutWarpPointer(x, y);
 }
 
@@ -224,10 +223,16 @@ static unsigned int getOSGModifiers(int glutModifiers)
     return result;
 }
 
-void fgOSOpenWindow(int w, int h, int bpp, bool alpha,
-                    bool stencil, bool fullscreen)
+void fgOSOpenWindow(bool stencil)
 {
+    int w = fgGetInt("/sim/startup/xsize");
+    int h = fgGetInt("/sim/startup/ysize");
+    int bpp = fgGetInt("/sim/rendering/bits-per-pixel");
+    bool alpha = fgGetBool("/sim/rendering/clouds3d-enable");
+    bool fullscreen = fgGetBool("/sim/startup/fullscreen");
+    WindowSystemAdapter* wsa = WindowSystemAdapter::getWSA();
     int mode = GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE;
+
     if(alpha) mode |= GLUT_ALPHA;
     if(stencil && bpp > 16) mode |= GLUT_STENCIL;
 
@@ -264,18 +269,21 @@ void fgOSOpenWindow(int w, int h, int bpp, bool alpha,
     int realh = h;
     viewer = new osgViewer::Viewer;
     gw = viewer->setUpViewerAsEmbeddedInWindow(0, 0, realw, realh);
+    GraphicsWindow* window = wsa->registerWindow(gw.get(), string("main"));
+    window->flags |= GraphicsWindow::GUI;
+    viewer->setDatabasePager(FGScenery::getPagerSingleton());
     // now the main camera ...
-    //osg::ref_ptr<osg::Camera> camera = new osg::Camera;
-    osg::ref_ptr<osg::Camera> camera = viewer->getCamera();
+    osg::Camera* camera = new osg::Camera;
     mainCamera = camera;
-    osg::Camera::ProjectionResizePolicy rsp = osg::Camera::VERTICAL;
     // If a viewport isn't set on the camera, then it's hard to dig it
     // out of the SceneView objects in the viewer, and the coordinates
     // of mouse events are somewhat bizzare.
     camera->setViewport(new osg::Viewport(0, 0, realw, realh));
-    camera->setProjectionResizePolicy(rsp);
-    //viewer->addSlave(camera.get());
-    globals->get_renderer()->getManipulator()->setUseEventModifiers(true);
+    camera->setProjectionResizePolicy(osg::Camera::FIXED);
+    Camera3D* cam3D = wsa->registerCamera3D(window, camera, string("main"));
+    cam3D->flags |= Camera3D::MASTER; 
+    // Add as a slave for compatibility with the non-embedded osgViewer.
+    viewer->addSlave(camera);
     viewer->setCameraManipulator(globals->get_renderer()->getManipulator());
     // Let FG handle the escape key with a confirmation
     viewer->setKeyEventSetsDone(0);
@@ -288,11 +296,6 @@ void fgOSOpenWindow(int w, int h, int bpp, bool alpha,
     globals->get_renderer()->setViewer(viewer.get());
 }
 
-// Noop; the graphics context is always current
-void fgMakeCurrent()
-{
-}
-
 bool fgOSIsMainCamera(const osg::Camera*)
 {
   return true;
@@ -302,3 +305,8 @@ bool fgOSIsMainContext(const osg::GraphicsContext*)
 {
   return true;
 }
+
+osg::GraphicsContext* fgOSGetMainContext()
+{
+    return gw.get();
+}